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

[bugfix] allow `modifier` helper to resolve built-ins like `on`

Open fivetanley opened this issue 2 years ago • 9 comments

partially fixes #19869

Due to GlimmerVM's assertion, this still does not fix the issue in strict mode. We also can't work around the strict mode limitation with an AST transform since Glimmer's transforms run first.

fivetanley avatar Jan 24 '24 20:01 fivetanley

Why does ember have its own record of this stuff? I would have thought this behavior (and fix) would be in glimmer-vm, since modifier is a keyword.

NullVoxPopuli avatar Jan 24 '24 21:01 NullVoxPopuli

@NullVoxPopuli I can't speak for the original authors', but the implementation currently rewrites

{{modifier "foo"}}

to

{{modifier (-resolve "modifier:foo")}}

via this AST transform.

The -resolve helper basically does a owner.hasRegistration check and doesn't use the resolver's logic at all.

I'm not sure why Ember has knowledge of these things vs these checks/etc being done in Glimmer itself.

fivetanley avatar Jan 24 '24 22:01 fivetanley

that's goofy.

I wonder if we can instead do all the resolution at build time instead of runtime.

I feel like I have either a very faint memory, or I made one up, of @ef4 mentioning something about this in the last week or two.

Like, automatically converting things to strict-mode so there's no runtime cost to any of this :thinking:

NullVoxPopuli avatar Jan 24 '24 22:01 NullVoxPopuli

The modifier helper has always been forbidden from accepting strings. It must not accept strings.

The same is true for the helper helper. Only component accepts them, and that only in non-strict mode, because it makes static analysis impossible.

Edit to correct: I see I'm misremember, but I know we have some limitation here. Perhaps it was only accepting string literals.

ef4 avatar Jan 24 '24 23:01 ef4

But also: do people not realize it's a very bad idea to be using this feature at all in new code in 2024? It moves you further away from adopting template tag and further away from adopting embroider. I promise I will work hard to break it in Ember 6.0.

If you need to yield a contextual modifier, Import your modifier in javascript and use the value directly. That works all the way back to at least Ember 3.28. That's what's aligned with template tag and embroider both.

ef4 avatar Jan 24 '24 23:01 ef4

@ef4 should this be the case for built-ins like on ? It feels cumbersome to have to find the import for this (I can't seem to find it in the documentation, had to source dive for it). I noticed @NullVoxPopuli opened several RFCs related to this, one of them making it so on doesn't need an import https://github.com/emberjs/rfcs/pull/997

fivetanley avatar Jan 24 '24 23:01 fivetanley

Closing this for now since I found a workaround to get around my problem. This could potentially be revisited in Glimmer itself if the RFCs in my previous comment are accepted. Here's a link to the workaround https://github.com/emberjs/ember.js/issues/19869#issuecomment-1909118910

fivetanley avatar Jan 24 '24 23:01 fivetanley

Adding more built-in keywords would probably be fine but that's very different from resolving strings to modifiers.

ef4 avatar Jan 25 '24 00:01 ef4

That is not correct, this is a long standing bug (linked issue in the original post). All of these accept strings in non-strict mode templates as specified in the RFC; we specifically agreed to make them all work consistently in normal templates and made the static resolution requirement strictly a strict-mode thing.

chancancode avatar Jan 25 '24 01:01 chancancode