-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
breaking: use quotes to differentiate custom element properties from attributes #12981
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
Conversation
🦋 Changeset detectedLatest commit: 6226b85 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
If we do these changes, then in the interest of backwards compat I propose to only do it in runes mode. That way existing code doesn't require a massive cleanup / you're not blocked if the code isn't under your control.
I'm also wondering if we should keep the "no property given, set as attribute instead" behavior - does it hurt / have unwanted consequences in any way?
If we go with this we also need to update prettier-plugin-svelte to leave quotes on custom elements as-is (right now it's always removed)
Am on board with making this a runes-mode-only thing
Not sure I understand?
Mind if I leave that to you? I'm unfamiliar with the codebase, so it'll be quicker that way... |
I mean that
Yeah no problem, was more a note to myself that we (I) need to adjust that if we go with this change. |
If there's no For example you might have a prop that doesn't have a corresponding accessor because it doesn't affect rendering (e.g. it's only referenced inside an event handler). It's a rare case but it could happen. With the PR as it currently is you can just leave a note for yourself explaining that: <!-- svelte-ignore custom_element_invalid_property — foo is a non-reactive property, not an attribute -->
<c-e foo={bar} /> |
There's also a case where the property isn't defined yet if the custom element definition is being lazy-loaded -- so I agree with Rich that being explicit makes sense. Old post of mine about that case: https://css-tricks.com/using-custom-elements-in-svelte/#aa-lazy-loading-custom-elements |
To be fair things would still be broken in that case — I wonder if we need to add some |
Closing as we decided to delay this until 6.0 |
Closes #12624 — I figured it would be worth having a branch to play with so that we can give it a proper spin.
Only two tests needed to be updated. The
attribute-custom-element-inheritance
test was very easy to fix because the warnings told me exactly what I needed to do. The other one was a tiny bit trickier because the attribute is reflected as a prop (squelching any warning) but needs to be present as an attribute in order to influence the CSS. Definitely a bit of an edge case, but flagging it nonetheless (and the"{red || undefined}"
is admittedly weird).On the whole, I like it — it gives control that doesn't exist today, and guides people towards the correct outcomes except in rather esoteric cases. I definitely like it more than ideas like
attr:foo
andprop:bar
for the reasons given here: #12624 (comment)Dynamic custom elements are currently a TODO (though the current heuristic obviously works fine for the existing tests)
Svelte 5 rewrite
Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (
main
).If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is
svelte-4
and notmain
.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint