V3 was entirely re-written with minimal API changes. V4 optimises V3 by minor refactors.
NextJsSSGThemeSwitcher, NextJsServerTarget, or ServerSideWrapper.NextJsSSGThemeSwitcher or NextJsServerTarget, you are free to use any target, whether as a wrapper or a sibling.ForceColorScheme and ForceTheme are no longer exported from nextjs-themes or nextjs-themes/client. Use nextjs-themes/force-color-scheme or nextjs-themes/force-theme instead.ColorSwitch have been shortened.Commit 6f17cce: Added additional CSS combinations to ensure seamless support for Tailwind.
[data-theme=] selectors function as before.ServerSideWrapper, NextJsServerTarget, or NextJsSSGThemeSwitcher, you need to convert forcedPages elements to objects shaped like { pathMatcher: RegExp | string; props: ThemeSwitcherProps }.resolvedColorScheme for more robust dark/light/system modes.[data-th=""] and [data-color-scheme=""] for dark/light theme variants.[data-csp=""] to style based on color scheme preference.Support for custom themeTransition.
themeTransition prop to the ThemeSwitcher component to apply a smooth transition when changing the theme.setThemeSet to set lightTheme and darkTheme together.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:
Next.js app router or server components, aside from updating the cookies policy if needed.localStorage. (You might need to update your cookies policy accordingly.)NextJsSSGThemeSwitcher in addition to ServerSideWrapper for Next.js. You no longer need to use a wrapper component that breaks static generation and forces SSR.app router (Server Components).defaultDarkTheme has been renamed to darkTheme.setDefaultDarkTheme has been renamed to setDarkTheme.defaultLightTheme has been renamed to lightTheme.setDefaultLightTheme has been renamed to setLightTheme.with 💖 by Mayank Kumar Chaudhari