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

{@html} broken after hydration since Svelte 4.0.2 #7557

Closed
1 task done
wackbyte opened this issue Jul 4, 2023 · 4 comments
Closed
1 task done

{@html} broken after hydration since Svelte 4.0.2 #7557

wackbyte opened this issue Jul 4, 2023 · 4 comments

Comments

@wackbyte
Copy link
Contributor

wackbyte commented Jul 4, 2023

What version of astro are you using?

2.7.3

Are you using an SSR adapter? If so, which one?

Node

What package manager are you using?

pnpm

What operating system are you using?

Linux (NixOS)

What browser are you using?

Firefox (Librewolf)

Describe the Bug

Since Svelte 4.0.2, the {@html} tag seems to be broken after being hydrated from props. On page load, it appears for a moment, but quickly disappears after hydration.

I think that this may originate from sveltejs/svelte#8880.

What's the expected result?

The {@html} tag should not disappear after being hydrated from props. This is its behavior in Svelte 4.0.1 and earlier.

Link to Minimal Reproducible Example

https://gitlab.com/wackbyte/svelte-html-hydration-broken

Participation

  • I am willing to submit a pull request for this issue.
@bluwy
Copy link
Member

bluwy commented Jul 4, 2023

This should be reported to Svelte. Looks like an unintended breaking change.

I tried debugging this but I can't quite figure out why it's happening. I noticed the <p> element that contains the @html is being detached here: https://github.com/sveltejs/svelte/blob/800f6c076be5dd87dd4d2e9d66c59b973d54d84b/packages/svelte/src/runtime/internal/Component.js#L145

A difference in your repro with a non-wrapper and wrapper islands, is that we're creating the Svelte component with hydratable: true directly vs letting Svelte create that nested Svelte component. We're creating the Svelte component like so:

new Component({
target,
props: {
...props,
$$slots: slots,
$$scope: { ctx: [] },
},
hydrate: client !== 'only',
$$inline: true,
});

Closing for now as it's not something that can be fixed in Astro.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Jul 4, 2023
@dummdidumm
Copy link

The problem is that the resulting HTML is invalid. In the reproduction, the result is <p><p>testing</p></p>. Nested p tags are invalid HTML so the browser shuffles things around in a weird way and then Svelte's hydration mechanism has no chance to pick up things correctly. If you ensure the HTML is valid (surrounding the {@html content} with a div for example) then the error should go away.

@wackbyte
Copy link
Contributor Author

wackbyte commented Jul 4, 2023

Ah, you're right, it seems to always happen with nested p tags. I'll go open an issue in the Svelte repo.

dummdidumm added a commit to sveltejs/svelte that referenced this issue Jul 4, 2023
When the HTML that is coming from raw html is invalid, the browser reshuffles things. Bail in that case to try to repair more often. Should help with withastro/astro#7557
dummdidumm added a commit to sveltejs/svelte that referenced this issue Jul 4, 2023
When the HTML that is coming from raw html is invalid, the browser reshuffles things. Bail in that case to try to repair more often. Should help with withastro/astro#7557
@wackbyte
Copy link
Contributor Author

wackbyte commented Jul 4, 2023

I was just setting up a repo to reproduce it in SvelteKit but it looks like it already got fixed :P

bleucitron pushed a commit to sveltefr/svelte that referenced this issue Jul 5, 2023
When the HTML that is coming from raw html is invalid, the browser reshuffles things. Bail in that case to try to repair more often. Should help with withastro/astro#7557
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

No branches or pull requests

3 participants