Skip to content
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

fix: better handle hydration of script/style elements #14669

Closed
wants to merge 2 commits into from

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Dec 11, 2024

Fixes #14624. We can better handle hydration of <script> and <style> elements when used with <svelte:element> and avoid the mismatch errors people are encountering.

Copy link

changeset-bot bot commented Dec 11, 2024

🦋 Changeset detected

Latest commit: b710030

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

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

Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@14669

@dummdidumm
Copy link
Member

While this fixes this case, I'm wondering how much more work it would be to instead generally not add hydration markers inside of blocks that only consist of a single child.

E.g. if you have this:

<div>
  {@render children()}
</div>

We're outputting this

<div>children conntent<!></div>

But we could output this instead

<div>children conntent</div>

@trueadm
Copy link
Contributor Author

trueadm commented Dec 11, 2024

While this fixes this case, I'm wondering how much more work it would be to instead generally not add hydration markers inside of blocks that only consist of a single child.

E.g. if you have this:

<div>
  {@render children()}
</div>

We're outputting this

<div>children conntent<!></div>

But we could output this instead

<div>children conntent</div>

I think this is actually different from that. In this case, there is no hydration marker, but $.append always does hydrate_next when hydrating.

@Rich-Harris
Copy link
Member

I don't love the fact that we're adding logic to every hydrate_next call — it feels like we should handle this special case inside the <svelte:element> code. Also, it's not just <script> and <style> that get this treatment, it's also <textarea> and <title>. Opened #14683 as an alternative

@trueadm trueadm closed this Dec 11, 2024
@trueadm trueadm deleted the hydrate-script branch December 11, 2024 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

svelte:element this={"script"} hydration_mismatch
3 participants