-
-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML Attribute and Property Rationalization #314
base: master
Are you sure you want to change the base?
Conversation
Sooo.... we're bringing back a variant of |
Seems like an implementation of core element modifiers #112 The old way still exist, but works in a different way under the hood. The above would only be in certain situations. @chadhietala maybe an example is required of when the above would be required and when not? |
@knownasilya Yes this is introducing more modifiers like #112 outlined. We are actively working on revising that RFC. This RFC may make more sense when #112 is updated. @Panman8201 Not quite. Weird Cases That Work TodayThese cases would require the
|
@chadhietala Would |
- _SubExpression_ | ||
|
||
### `{{on}}` Runtime Semantics | ||
The `{{on}}` modifier is installed on the element once the element is placed into the DOM. At that time we will call `addEventListener` with the `EventName` and `EventCallBack`. Since an element can have multiple `{{on}}` modifiers installed on it, we will associate the `EventCallBack` and `EventName` with the element so we can call `removeEventListener` during destruction of the element. The `addEventListener` will be called with `{ capture: true }` if `EventOptions` are not passed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chadhietala Why capture phase as default instead of bubbling phase? Any reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be outdated. There was a separate RFC for {{on}}
modifier, which is merged. It has been implemented and shipped as part of Octane.
I dislike this for DX reasons mostly. It's pushing a lot of manual labor to developers and additional complexity to the templates. I'd argue that the templates will get unreadable with all of the sigils in them, it's already somewhat hard to read some templates when there is a lot of stuff going on. Also, do we really need yet another way to define actions / events? I think our current setup is complex enough: I guess my main issue is that the current setup mostly works and is pretty convenient to work with. It feels like this proposal optimizes for the edge cases instead of the "90%" use case. Maybe an alternative would be to go the other way, meaning leave the heuristics as they are (or improve if necessary) and provide tools (like |
@balinterdi Yes. @piotrpalek For what it's worth I help maintain an app that has 120,000 lines of handlebars (2589 templates). I did a quick audit of just |
@chadhietala I've tried to collect my thoughts about this proposal: What I don't like:
What I wish it would looks like:
Useful discussions from the React ecosystem: |
While I'm not opposed to this RFC per-se, I think we're approaching it the wrong way. I'd much rather see #112 advance and hold this back. Once we have element modifiers we should experiment with the proposed API in this RFC (which sounds reasonable to me) in addon-land and eventually promote it into core. But in any case I'm agains adding more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have struggled recently with custom elements and ember a lot. This RFC would simplify that a lot.
I'm wondering that it doesn't mention backward compatibility. Setting values as attribute which have been set as property before is a breaking change, isn't it?
There seems to be a need to:
- Allow developers to opt-in to attributes only semantics.
- Deprecate the current behavior.
Maybe an optional feature?
- _NumberLiteral_ | ||
|
||
### `{{prop}}` Runtime Semantics | ||
The `{{prop}}` modifier is installed on the element once the element is placed in the DOM. At that time it will loop over the `HashPair`(s) setting the properties on to the element. No normalization is done for the `Key` or `Value`. In other words what you see is what you get. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timing is problematic for custom elements.
Custom elements (web components) have lifecycle hooks similar to @ember/component
. One of them is connectedCallback
. It's executed when the element is insert into the DOM.
The property is not available in that hook if {{prop}}
modifier runs after the element had been insert into DOM.
I'm aware that this is a limitation of modifiers in general and not related to {{prop}}
modifier proposed here only. The limitation is discussed in detail at #652.
- _SubExpression_ | ||
|
||
### `{{on}}` Runtime Semantics | ||
The `{{on}}` modifier is installed on the element once the element is placed into the DOM. At that time we will call `addEventListener` with the `EventName` and `EventCallBack`. Since an element can have multiple `{{on}}` modifiers installed on it, we will associate the `EventCallBack` and `EventName` with the element so we can call `removeEventListener` during destruction of the element. The `addEventListener` will be called with `{ capture: true }` if `EventOptions` are not passed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be outdated. There was a separate RFC for {{on}}
modifier, which is merged. It has been implemented and shipped as part of Octane.
The drawback of this is that we are making developers know about some nuanced details of the updating semantics of HTMLElements. The tradeoff is that serve-side rendering works as expected and developers have a clear path for adopting natvie web components. | ||
|
||
## Alternatives | ||
There are a couple different alternatives. We could keep `{{textarea}}` and `{{input}}` around and somehow special case them as special components that always set properties. However, this means we would have to expand helper support to things like `<option />`. It's also odd to be creating primitives just for the sake of updating semantics. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may have missed it but is this RFC proposing to deprecate <Textures>
and <Input>
built-in components?
|
||
- Can we remove `TextSupportMixin`? | ||
- Can we remove `{{textarea}}`? | ||
- Can we remove `{{input}}`? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how these questions are related to this specific RFC.
- Can we remove `{{textarea}}`? | ||
- Can we remove `{{input}}`? | ||
- Do we really want `{{on}}` to have updating semantics for `EventName`? | ||
- Who is responsible for binding the context for the `EventCallback`? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two questions seem to be outdated as on modifier has already been shipped.
## Drawbacks | ||
The drawback of this is that we are making developers know about some nuanced details of the updating semantics of HTMLElements. The tradeoff is that serve-side rendering works as expected and developers have a clear path for adopting natvie web components. | ||
|
||
## Alternatives |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a third option we could stick with the current rules but additionally provide fine granular control to developer where needed. E.g
{{attr}}
and {{prop}}
modifiers that run before the element is insert into the DOM.
Is there still interest in moving this forward? If so, I can help get it finalized. |
Rendered