title |
---|
Migration Guide |
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
NextJsSSGThemeSwitcher
orNextJsServerTarget
, you are free to use any target, whether as a wrapper or a sibling.
ForceColorScheme
andForceTheme
are no longer exported fromnextjs-themes
ornextjs-themes/client
. Usenextjs-themes/force-color-scheme
ornextjs-themes/force-theme
instead.- The class names for
ColorSwitch
have been shortened.
-
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 convertforcedPages
elements to objects shaped like{ pathMatcher: RegExp | string; props: ThemeSwitcherProps }
. - Use
resolvedColorScheme
for 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
-
Support for custom
themeTransition
.- Provide the
themeTransition
prop to theThemeSwitcher
component to apply a smooth transition when changing the theme. - Use
setThemeSet
to setlightTheme
anddarkTheme
together.
- Provide the
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.js
app 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
NextJsSSGThemeSwitcher
in addition toServerSideWrapper
forNext.js
. You no longer need to use a wrapper component that breaks static generation and forces SSR. - For more details, visit With Next.js
app
router (Server Components).
defaultDarkTheme
has been renamed todarkTheme
.setDefaultDarkTheme
has been renamed tosetDarkTheme
.defaultLightTheme
has been renamed tolightTheme
.setDefaultLightTheme
has been renamed tosetLightTheme
.
with 💖 by Mayank Kumar Chaudhari