ember.js icon indicating copy to clipboard operation
ember.js copied to clipboard

[Bug] A yielded 'fn' from a component is incorrectly rendered as [object Object]

Open basz opened this issue 2 years ago • 4 comments

🐞 Describe the Bug

A yielded 'fn' from a component is incorrectly rendered as [object Object]

🔬 Minimal Reproduction

Inside a component I have this

{{yield
          (hash
            resourceExtruderCurrentTemperature=(fn ExtruderCurrentTemperature this.printerManager)
          )
        }}

I use the 'fn' helper to be able to add more positional arguments

😕 Actual Behavior

This renders [object Object]

<EmbeddedPrinterComponent @printer={{printer}} as |e|>
{{e.resourceExtruderCurrentTemperature true}}
</EmbeddedPrinterComponent>

🤔 Expected Behavior

Should render 3.5

<EmbeddedPrinterComponent @printer={{printer}} as |e|>
{{e.resourceExtruderCurrentTemperature true}}
</EmbeddedPrinterComponent>

🌍 Environment

ember-cli: 5.4.0 node: 18.18.0 os: darwin arm64 browser: chrome

➕ Additional Context

Using the let helper does render the expected output.

<EmbeddedPrinterComponent @printer={{printer}} as |e|>
{{#let (e.resourceExtruderCurrentTemperature true) as |value|}}{{value}}{{/let}}
</EmbeddedPrinterComponent>

@NullVoxPopuli suggested this might be a bug in 'fn', hence this report.

basz avatar Dec 08 '23 16:12 basz

without digging in to fn, the reason why I think it could be a bug in fn is that these should be equiv:

{{#let (fn someFn 1) as |partiallyApplied|}}

  {{ (partiallyApplied) }}

{{/let}}

and

{{ (someFn 1) }}

as long as fn goes through the helper-manager system, it doesn't matter what someFn is.

NullVoxPopuli avatar Dec 08 '23 16:12 NullVoxPopuli

Here is a reproduction, showing that this happens with Resources... but even worse: errors with Classic Class and function helpers. With the classic constructs, we get an error saying that call isn't a function, which leads me to believe that we never implemented native helper-manager aware partial application, and only used JavaScript's built in .call behavior.

My hypothesis is that the helper and Helper from @ember/component/helper aren't compatible with fn because neither are functions.

NullVoxPopuli avatar Dec 08 '23 17:12 NullVoxPopuli

I just remembered!!!

We have (helper) and (modifier) and (component) for partial application of those specific concepts.

Here is the above reproduction, fixed, by using (helper)

NullVoxPopuli avatar Dec 08 '23 17:12 NullVoxPopuli

So maybe the real question here is -- why do we have 4 ways to partially apply arguments? and can we get that down to 1?

NullVoxPopuli avatar Dec 08 '23 18:12 NullVoxPopuli