Migration Guide
June 24, 2024 ยท View on GitHub
Migrating to V3 and V4
V3 was entirely re-written with minimal API changes. V4 optimises V3 by minor refactors.
- No more cookies.
- You no longer need to use
NextJsSSGThemeSwitcher,NextJsServerTarget, orServerSideWrapper. - Flash of Unstyled Content (FOUC) is now handled by an injected script.
- If you have been using these components, they will have no effect. We recommend removing them.
- There is no need to use sibling selectors. Without
NextJsSSGThemeSwitcherorNextJsServerTarget, you are free to use any target, whether as a wrapper or a sibling.
Breaking Changes - these should only affect a very small fraction of library users
ForceColorSchemeandForceThemeare no longer exported fromnextjs-themesornextjs-themes/client. Usenextjs-themes/force-color-schemeornextjs-themes/force-themeinstead.- The class names for
ColorSwitchhave been shortened.
Migrating from V1 to V2
Major Changes
-
Commit
6f17cce: Added additional CSS combinations to ensure seamless support for Tailwind.- No changes are required for client-side code as
[data-theme=]selectors function as before. - If you are using
ServerSideWrapper,NextJsServerTarget, orNextJsSSGThemeSwitcher, you need to convertforcedPageselements to objects shaped like{ pathMatcher: RegExp | string; props: ThemeSwitcherProps }. - Use
resolvedColorSchemefor more robust dark/light/system modes. - Use combinations of
[data-th=""]and[data-color-scheme=""]for dark/light theme variants. - Use
[data-csp=""]to style based on color scheme preference.
- No changes are required for client-side code as
Minor Changes
-
Support for custom
themeTransition.- Provide the
themeTransitionprop to theThemeSwitchercomponent to apply a smooth transition when changing the theme. - Use
setThemeSetto setlightThemeanddarkThemetogether.
- Provide the
Motivation
For server-side syncing, cookies and headers are required. This means that this component and its children cannot be static and will be rendered server-side for each request. To avoid the wrapper, only the NextJsSSGThemeSwitcher will be rendered server-side for each request, while the rest of your app can be served statically.
Consider the following when migrating to V2:
- No changes are required for projects not using the
Next.jsapp router or server components, aside from updating the cookies policy if needed. - Persistent storage now uses cookies instead of
localStorage. (You might need to update your cookies policy accordingly.) - We have introduced
NextJsSSGThemeSwitcherin addition toServerSideWrapperforNext.js. You no longer need to use a wrapper component that breaks static generation and forces SSR. - For more details, visit With Next.js
approuter (Server Components).
Migrating from V0 to V1
defaultDarkThemehas been renamed todarkTheme.setDefaultDarkThemehas been renamed tosetDarkTheme.defaultLightThemehas been renamed tolightTheme.setDefaultLightThemehas been renamed tosetLightTheme.
with ๐ by Mayank Kumar Chaudhari