-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Hydration mismatch not reconciling properly #14909
Comments
You should use |
@paoloricciuti That seemed to work. Q1. |
I think the CLI generator assume that you will have no content of your own and just an empty div. In that case mount is correct because there's no html to hydrate. This is also why I don't think it should spit out an error...mount "adds" to the element without even looking at the content and I think it's fair (let's say you want to mount multiple independent components to the same div). Why are you expecting an hydration mismatch? From what I understood you are generating the correct html on the server (p.s. a reproduction is appreciated even if it includes a different programming language) |
I'm not generating the correct html (just an approximate) because I haven't quite solved how to generate the EXACT DOM on the server. Even when I replace it with text "SAMPLE BODY", there is still not hydration mismatch error. |
Then we absolutely need a reproduction for this, at very minimum you should provide the generated html and how you are actually using it |
@paoloricciuti I'll create a sample project tomr. Almost midnight here. |
I think we can clearly state which attributes (even tho you already get the warning)...as per "always preferring client side" I think this is a very niche use and I can't recall on the top of my head the amount of code we would need to unlock that but I suspect is not minimal. |
Here is instructions on how to reproduce
Change <!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Svelte + TS</title>
</head>
<body>
<div id="app">SAMPLE BODY</div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
|
@tanhauhau I know you've worked on the hydration code. |
Ok i took a look, that is simply because by default hydrate falls back to |
Why am I not notified of the hydration error? Isn't that the point of hydration_mismatch error. |
The error is there to show you when there's an hydration mismatch but if svelte can "correct that" it falls back to removing the server content and just mounting the component |
So essentially it is ALWAYS PREFER CLIENT SIDE RENDERING??? |
Describe the bug
For the purposes of explaining the bug:
Let's say my index.html contains this:
Let's say svelte will manage the
app
div on the client.app
div tag. (NB: "SAMPLE BODY" text was just an example, not the real rendered html output. Also that text was not in the index.html file passed to the JS runtime!)app
div tag with the html from step 4.The BUG
app
tag instead of replacing it. (i.e. for the example at the top, it will say "SAMPLE BODY" AND THEN the acual client-side rendered DOM. (Note: React replaces instead of appends)Extra Issue in Documentation:
There are 3 relevant errors:
The docs state a "hacky" way to force a client-side update:
Proposal 1
I propose that there is an option added to the compiler to ALWAYS PREFER CLIENT SIDE RENDERING for scenarios such as mine.
Proposal 2
In the docs, it should clearly state EXACTLY which attributes the below applies to (i.e. what else other than
src
?)hydration_attribute_changed:
hydration_html_changed:
Reproduction
N/A (requires code from another programming language)
Logs
No response
System Info
Severity
blocking all usage of svelte
Thanks @tanhauhau for your video on hydration.
The text was updated successfully, but these errors were encountered: