suppress React 19 script warning by not rendering ThemeScript on client - #386
suppress React 19 script warning by not rendering ThemeScript on client#386jakubwarkusz wants to merge 1 commit into
Conversation
|
This is also fixed by my own library themes.wrksz.dev that's a near drop-in replacement for next-themes. See this |
React 19.2 warns because next-themes 0.4.6 renders its bootstrap script again on the client, where React-created script elements do not execute.\n\nPatch both CJS and ESM builds so ThemeScript remains in SSR output but returns null on the client. This follows upstream pacocoursey/next-themes#386 while pacocoursey/next-themes#385 remains open and no fixed release is available.\n\nRemove the patch after upgrading to an upstream release that contains the fix.
|
+1 — we ran into the same We shipped an equivalent fix via This looks like the correct minimal fix. Is there anything blocking a merge here? CI is passing — happy to help if a rebase or test additions would help it land. |
Problem
Since Next.js 16.2
ThemeProvidertriggers a browser warning:Reported in #385.
Fix
Return
nullfromThemeScriptwhen running on the client(
typeof window !== 'undefined'). The script only needs to be present in theSSR-generated HTML where the browser executes it once before hydration. After
that it is no longer needed.
The existing
nonceprop, which was already gated behindtypeof window === 'undefined', is simplified accordingly.