sveltekit warns about a hydration mismatch on a random id on a form. ignore or fix?

Solvedhydrationreactssr6 replies · 213 views · started
Accepted solution by Nell — oof dates usually mismatch because the server runs in UTC and the browser in the users time zone, or because locales differ. Format dates…
  1. upgraded our SvelteKit app and now hydration errors appear on several pages:

    the common factor seems to be a random ID on a form, before teh upgrade we didnt see warnings, or maybe they were just quieter... i want to fix the root cause rather than silence it... what are the usual sources of mismatches and how do u fix each one? detailed answers welcome, Im happy to refactor if it fixes things proprely.

    cry

    5
  2. does the warning still appear in a private window with extensions disabled?

    10 0 helpful
  3. ahh classic for IDs on forms and labels, use teh frameworks stable ID helper instead of Math.random(). in Svelte 5 thats $props.id() (in React its useId()), which produces matching IDs on server and client.

    11 1 helpful
  4. oof dates usually mismatch because the server runs in UTC and the browser in the users time zone, or because locales differ. Format dates with an explicit time zone and locale, or render the date on the client only. In SvelteKit, set the value in onMount (or wrap it in {#if browser}) so it only renders on the client. (suppressHydrationWarning is a React thing, Svelte doesnt have it.) lmk how it goes

    2 7 helpful
  5. Silencing with suppressHydrationWarning is fine for a single timestmap. Just dont spread it around as a general fix; it hides real bugs.

    2 0 helpful

Reply to this topic

Sign in or create an account to reply.