-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore: remove redundant hydration for $props.id() #15409
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: 611a280 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 |
|
|
This will likely conflict with #15403 (just putting this out there)...also this strategy feel somewhat risky for some reason 😁 but I'll take a proper look later |
|
Of course PR 15403 takes priority, but I don't think that this poses a conflict. |
|
I've also tried to create a tinybench with reading text comment+one extra next sibling vs get attribute and the latter is significantly slower so I'm even less convinced is worth it to remove the comment https://svelte.dev/playground/f96ae09ddfdc45fca8d230d9f48de9af?version=5.20.5 |
|
However I think we might be able to do something similar to this but kinda opposite which is what I was proposing before: if the first comment is compatible (I think if blocks are not compatible for example) we could stick the id there so that we don't need an extra comment and we need to change the props id function just to know if we need to call hydrate next or not. I'll try to put up a PR if you don't beat me to it 😁 |
I tried that without success : too much hydration errors :( |
I was trying right now... didn't got at the client side yet tho |
|
I think the added complexity and runtime bundle size overhead is not worth this - |
|
I agree — it's a creative solution but we already have quite a lot of complexity around hydration, and I worry that the more we add the harder it becomes to make other (potentially more substantial) changes. I'll close this and #15417 |

Just a little improvement for the hydration of
$props.id(), which I had initially thought of without having the time to do it.Currently using
$props.id()adds a comment like<!--#s1-->at the beginning of the component, for hydration.So a component like that :
will be hydrated to :
But in this case, we can retrieve the value of
props.id()from theidattributeWith this PR, we check the presence of the
$props.id()value on attributes at compile time.So the hydration comment will be removed :
The hydration comment is still required when the
$props.id()value is absent from attributes, or when the component don't starts with a regular element (it's not possible with<svelte:element>because of his own hydration comments).Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lint