Why does a random ID on a form render differently on the server in SvelteKit???

hydrationreactssr8 replies · 150 views · started
  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 wanna fix teh root cause rather than silence it. What are the usual sources of mismatches and how do you fix each one?? Detailed answers welcome, Im happy to refactor if it fixes things properly.

    1
  2. for user-specific values like theme or login state, make the server know them too: read a cookie on the server and render the same value. if the server truly can't know, render a neutral state first and swap after hydration, or render that component client-only (dynamic(..., { ssr: false }) in Next.js, <ClientOnly> in Nuxt).

    lol

    0 6 helpful
  3. hmmmm quick q is hydration even worth bothering with or should i just leave it

    7 0 helpful
  4. lol this thread is gold seriously need help here 😭

    24 9 helpful
  5. oh ive been there lol invalid HTML nesting also causes mismatches, because teh browser repairs the HTML differently than your components expect. common cases: a <div> inside a <p>, or a link inside another link. The error message often names the element; check its parent.

    9 5 helpful
  6. ahh classic following, having the same problem 😅 which version are you on? good luck man!

    12 12 helpful
  7. dates usually mismatch because the server runs in UTC and the broswer in the users time zone, or cuz locales differ. format dates with an explicit time zone and locale, or render the date on the client only. for a single timestamp element, React supoprts suppressHydrationWarning on that element. hope that helps :)

    34 0 helpful
  8. also lol unrelated but anyone elses coffee machine also judging them today

    3 0 helpful

Reply to this topic

Sign in or create an account to reply.