[V2] Web SSR/static export: root theme class from the server HTML survives hydration, so dark mode renders light screens with dark sheets
Current Behavior
With SSR or a static export, TamaguiProvider renders defaultTheme as a class on its two root wrappers (t_light _dsp_contents, t_light is_Theme). With the Expo guide's defaultTheme={colorScheme!}, the server renders light and a browser that prefers dark hydrates with dark. React 19 does not patch attributes during hydration, and later renders produce the same value, so the wrappers stay t_light while body gets t_dark from an effect. In dark mode the result is light screens with dark sheets and toasts (portals). Production logs no warning, and expo start --web does not hydrate, so the bug never shows up in dev.
Cause: ThemeProvider forces the class onto the wrappers when addThemeClassName is undefined (ThemeProvider.tsx L13–44). In 1.x, @tamagui/config/v3 set themeClassNameOnRoot: true, and the upgrade guide says addThemeClassName replaces it. But the v2 @tamagui/config/v3 does not set it (v3.ts L113–118), so v1 apps silently switch to putting the class in the HTML. The three documented defaults also disagree: the JSDoc says html, the docs say false, and the code treats undefined as a third mode. The v4/v5 configs set 'html' and are fine. 3.0.0-beta.1479.1 has the same logic.
Expected Behavior
After hydration, the root wrappers should match the client theme, the same as body.
Possible fixes, in order of preference:
- Don't render the scheme class on the root wrappers until
useDidFinishSSR()is true. - Make
addThemeClassName: 'html'the effective default, or at least set it in@tamagui/config/v3. - Document that
defaultThememust match the server render, and align the documented defaults.
Workaround we ship (addThemeClassName: 'html' also works):
const dark = useDidFinishSSR() && colorScheme === 'dark'
return <TamaguiProvider config={config} defaultTheme={dark ? 'dark' : 'light'}>Tamagui Version
2.7.7 (latest), unchanged on main @ 0eb99e3. Also reproduced on 3.0.0-beta.1479.1.
Not present on 1.144.4 with the same app.Platform (Web, iOS, Android)
Web with SSR or static export (Expo Router web.output "static"). Native is not affected.Reproduction
https://github.com/dieguezguille/tamagui-web-ssr-theme-hydration-repro
Root layout from the Expo guide, @tamagui/config/v3 with no overrides, one screen with a modal Sheet.
pnpm install
pnpm export # sets TAMAGUI_DISABLE_SLIDER_INTERVAL=1 (separate slider bug)
pnpm serve # in another terminal
pnpm check # headless Chrome, prefers-color-scheme dark: exits 1 on main
main (2.7.7), dark: wrappers stay t_light, body is t_dark
screen rgb(255, 255, 255), sheet rgb(5, 5, 5)
branches: with-workaround ok, v3-beta mismatch, v1 (1.144.4) okSystem Info
macOS 27.0 (arm64), Node 24.13.0, pnpm 11.5.2, headless Chrome 153
expo 55.0.31, expo-router 55.0.18, react 19.2.0, react-native-web 0.21.3
tamagui / @tamagui/config 2.7.7Source: tamagui/tamagui