-
-
Notifications
You must be signed in to change notification settings - Fork 13
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 warning on console for svelte 5 #95
Comments
I wrapped the ModeWatcher component in a browser if block, not sure if that's the way to go about it but it seems to work for me... |
No. if you're using SvelteKit don't do this. It will cause a blink from light->dark or dark->light on initial page load. |
I copied the mode-watcher folder from node_modules to $lib/components to mess around and try to fix it, and the warning disappeared 🤷 |
Do you have a real/better workaround? |
Still wondering what to do here |
According to @huntabyte on discord:
Here is the error line:
Maybe together we can solve this :) J |
Thanks for the research 👍 Unfortunately I'm having trouble wrapping my head around the CSS variable solution |
I take it back, yeah I don't think a CSS only solution could work in this case. Without a cookie based solution in a hook file to persist the dark mode (almost a different thing), I'm wondering if a J |
That is what i usually do in my projects. Initially Set the Theme with an inline script placed in app.html and handle subsequent changes within the Theme component |
Should we consider for a second why my warning disappeared when I moved the script from |
Or why it suddenly appeared in Svelte 4. In Changing this: {#if trueNonce}
<!-- eslint-disable-next-line svelte/no-at-html-tags prefer-template -->
{@html `<script nonce=${trueNonce}>(` +
setInitialMode.toString() +
`)(` +
JSON.stringify(initConfig) +
`);</script>`}
{:else}
<!-- eslint-disable-next-line svelte/no-at-html-tags prefer-template -->
{@html `<script>(` +
setInitialMode.toString() +
`)(` +
JSON.stringify(initConfig) +
`);</script>`}
{/if} to this: <!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html `<script${trueNonce ? ` nonce=${trueNonce}` : ''}>(` +
setInitialMode.toString() +
`)(` +
JSON.stringify(initConfig) +
`);</script>`} Seems to fix the problem and get rid of the warning. Should we make a PR? That being said, I'm not sure if J |
@jdgamble555 Maybe I'm missing something, but wouldn't the code with the conditional expression produce the exact same thing as the one with the conditional statement? What am I not seeing? |
Honestly, no idea the technical difference, but it seems to work. I'm also not sure why there was an error in Svelte 4... Anyone else tested this to be sure it works? |
your fix works perfect for me. i ran into this exact same issue |
@huntabyte - Could we get this updated (as long as you see nothing wrong with it) ? Thanks! J |
Is this warning only happening to you all running Svelte 5? I'm in the process of working on the Svelte 5 version of mode-watcher so I'd prefer to handle this along with the hooks.server related helpers in the |
In the meantime, if someone wants to submit a PR to get this addressed in |
Yes, this happens for Svelte 5 users. This should hopefully temporarily solve the problem until the runes version. J |
Is this temp fix working for folks? I'm still seeing the warning after upgrading to 0.5.0:
Not a big deal, just wondering... |
Are you using light or dark mode on your client? @coryvirok |
System for the most part but I just tested with both light and dark and they all show the warning. |
My guess as to why this is happening is that the information we use, like To fully prevent possible server/client discrepancies, we'd need to use a cookie and provide a helper to enter the sequence of the I'll look into workarounds to get this warning to go away, it's just going to degrade the DX of mode-watcher. |
This is crazy to me that this works when it is changed in The However, this was not a problem until Svelte 5 decided to use stricter warnings. which makes you wonder if there is a "hack" or "work-around" in Svelte 5 as well.
Perhaps $effect.pre() ? Side Note: There should also be a hook for logged in users to save the dark mode status to the DB and hydrate it from the server. J |
This is strange.
Of course 😃 |
I am also still getting the warning still.
|
It's not an error @rzzo it's a warning |
Describe the bug
Getting hydration issue for svelte 5 project. I just upgraded to svelte 5 on sveltekit project.
Reproduction
Upgrade the svelte version to 5 and having this issue.
Logs
svelte] hydration_html_changedThe value of an
{@html ...}
block in node_modules/.pnpm/[email protected][email protected]/node_modules/mode-watcher/dist/mode-watcher.svelte changed between server and client renders. The client value will be ignored in favour of the server valueSystem Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: