Skip to content

Adding theme preload causes hydration error #1038

Answered by tylersayshi
bostjanpisler asked this question in Q&A
Discussion options

You must be logged in to vote

middleware that changes the rendered result before it reaches the client will cause a hydration error

you could use suppressHydrationError in this case since you are deliberately making the change between the client and server: https://react.dev/reference/react-dom/client/hydrateRoot#suppressing-unavoidable-hydration-mismatch-errors

It might be better though to set the theme preload in your RSC with unstable_getHeaders instead of needing the middleware

import { unstable_getHeaders } from 'waku/server';

...

<html lang={"${lang}"} class={themeFromHeaders}>

you'll need to use the root element api too: https://waku.gg/blog/root-element-api

hope this helps!

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@bostjanpisler
Comment options

@bostjanpisler
Comment options

Answer selected by bostjanpisler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants