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

Bug with SSR and Hydration (Probably Caused by @html) #7115

Closed
Acmion opened this issue Nov 15, 2021 · 6 comments · Fixed by #6946
Closed

Bug with SSR and Hydration (Probably Caused by @html) #7115

Acmion opened this issue Nov 15, 2021 · 6 comments · Fixed by #6946

Comments

@Acmion
Copy link

Acmion commented Nov 15, 2021

Describe the bug

Using multiple {@html variable} can make SvelteKit behave strangely. Essentially, the application is first SSR rendered into the correct state, then the hydration kicks in and incorrectly mutates the state.

This means that the app flickers and that the resulting state is incorrect.

Reproduction

https://github.com/Acmion/svelte-kit-ssr-bug

Logs

-

System Info

System:
    OS: Windows 10 10.0.19042
    CPU: (4) x64 Intel(R) Core(TM) i5-2500K CPU @ 3.30GHz
    Memory: 1.64 GB / 7.97 GB
  Binaries:
    Node: 14.16.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.11 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (95.0.1020.53)
    Internet Explorer: 11.0.19041.1202
  npmPackages:
    @sveltejs/kit: next => 1.0.0-next.196
    svelte: ^3.42.6 => 3.44.1

Severity

annoyance

Additional Information

It is relatively easy to work around this problem by, for example, wrapping the {@html variable} statements in divs, like this:

<div>{@html variable}</div>

However, it is relatively hard to detect and understand what is causing this issue.

@rmunn
Copy link
Contributor

rmunn commented Nov 16, 2021

Although the reproduction requires Svelte-Kit, I suspect the ultimate cause of the bug might be the @html hydration code, which lives in the Svelte repo. Specifically, in the claim_html_tag function of src/runtime/internal/dom.ts and related functions. If I'm right, it should be possible to create a REPL repro demonstrating the bug using new Component({ hydrate: true }).

@Acmion
Copy link
Author

Acmion commented Nov 16, 2021

Yes, you are probably right.

I tried to reproduce the problem in the Svelte REPL (https://svelte.dev/repl), but got the following error:

options.hydrate only works if the component was compiled with the `hydratable: true` option

@benmccann
Copy link
Member

@hbirler FYI in case you were interested in any more hydration edge cases

@baseballyama
Copy link
Member

@rmunn

Are you working on this issue?
If not, I would like to work on it.

@rmunn
Copy link
Contributor

rmunn commented Nov 20, 2021

@baseballyama - No, I've got my hands full with other issues at the moment.

@baseballyama
Copy link
Member

@rmunn OK! I created PR!

@benmccann benmccann transferred this issue from sveltejs/kit Jan 9, 2022
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 a pull request may close this issue.

4 participants