Existing theme setup
What init does when your app already has a theme provider, and how to finish the setup by hand.
What init checks first
uitheme-cli init first detects the framework of the app. Then it looks for a
theme setup that the app already has. It does this before it adds the UI-Theme
provider, so it never puts a second provider next to the first one.
init sorts the app into one of these classes:
| Class | What init finds | What init does | Exit code |
|---|---|---|---|
| None | No theme setup. | Adds the UI-Theme provider. | 0 |
| UI-Theme, correct | The right UI-Theme provider for the framework. | Changes nothing. | 0 |
| UI-Theme, wrong or partial | A UI-Theme provider that does not fit the framework, or a setup from an earlier init. | Upgrades the setup in place. | 0 or 2 |
| UI-Theme 1 | @ui-theme/web or uitheme-vue. | Asks you to run uitheme-cli migrate first. | 2 |
| next-themes | next-themes in a Next.js, TanStack Start, or Vite React app. | Converts the provider and the hooks, then removes next-themes. | 0 or 2 |
| shadcn provider | The theme provider from the shadcn dark mode guide for Vite or TanStack Start. | Rewrites the provider file on top of UI-Theme. | 0 or 2 |
| Other library | Another theme library, such as @nuxtjs/color-mode. | Changes no theme file. Prints the next steps. | 2 |
| Custom provider | Your own theme provider or theme script. | Changes no theme file. Prints each signal that it found. | 2 |
| More than one class | Two or more of the classes above. | Converts nothing. Prints the classes. | 2 |
Exit code 2 means that a step remains for you. In every class, init still
writes the theme CSS, uitheme.json, and the cn utility, and installs
uitheme-web.
Choose what init does
When init finds a theme setup, it names the setup and the file. It lists each
signal with its file and line. Then it asks one question and shows only the
choices that apply:
| Choice | Result | Available for |
|---|---|---|
convert | Rewrites the setup to UI-Theme and removes what it replaces. | next-themes, shadcn provider |
manual | Leaves the setup alone. You finish the setup yourself. | Every class |
alongside | Writes the UI-Theme provider to a separate file. init does not add it to your app. | Custom provider in a React app |
The first choice is the default. Press Enter to accept it.
init does not ask in these cases:
- You pass
--yes. - You pass
--dry-run. - The run has no terminal, for example in CI.
Then init converts when a converter applies. In all other cases, it uses
manual. Use --existing to choose without a question:
If the choice does not apply to the class, init says so and uses manual.
--overwrite does not choose a conversion. It only replaces control files that
differ from the uitheme version.
Preview the result before you apply it:
The plan shows the line existing theme setup: <class> -> <choice>, the signals,
and the files to change. When init removes a package, the plan shows the command.
A conversion is all or nothing. If init cannot convert one part, it changes no
theme file. It prints the file, the line, and the form that stopped it. It then
continues with manual and exits with code 2.
next-themes
init looks for next-themes only in React apps: Next.js, TanStack Start, and
Vite React. It checks package.json and the source files.
With convert, init does these steps:
- It changes the imports from
next-themes. See the mapping. - It changes the props of your
ThemeProvider. - It checks every use of
useTheme. - It removes
next-themeswith the package manager of the app.
init removes the package only when package.json lists it. If the package is
listed but no source file imports it, init only removes the package. If the
removal fails, init prints the command to run and exits with code 2.
In TanStack Start, init also asks you to add TanStackStartThemeScript to the
document head. Give it the same storageKey, defaultTheme, and themes as the
provider. See the TanStack Start guide.
Imports
init replaces the import from next-themes. It keeps your local names, so the
rest of the file does not change.
next-themes | Next.js | TanStack Start | Vite React |
|---|---|---|---|
ThemeProvider | NextUIThemeProvider | TanStackUIThemeProvider | UIThemeProvider |
useTheme | useNextUITheme | useTanStackUITheme | useUITheme |
ThemeProviderProps | NextUIThemeProviderProps | TanStackUIThemeProviderProps | UIThemeProviderProps |
| Import path | uitheme-web/next | uitheme-web/react | uitheme-web/react |
A file that has import { useTheme } from 'next-themes' gets this line in Next.js:
Prop mapping
| Prop | Result |
|---|---|
attribute="class" | Removed. UI-Theme uses class by default. |
attribute="data-theme" | Next.js only. Kept. In other frameworks, init stops. |
No attribute | Next.js: init adds attribute="data-theme", because next-themes uses that attribute by default. Other frameworks: init stops. |
defaultTheme | Kept. The value must be light, dark, or system. |
enableSystem | Removed. See themes. |
enableColorScheme | Removed. enableColorScheme={false} stops init. |
themes | Rewritten. It may list only light and dark. init adds system unless you set enableSystem={false}. |
disableTransitionOnChange | Kept. disableTransitionOnChange={false} is removed. |
storageKey, nonce | Kept. |
With enableSystem={false}, init also adds themes={['light', 'dark']} and
defaultTheme="light" when your provider does not set them. In TanStack Start,
init adds systemThemeMode="js".
init stops on any other prop, on a prop spread, and on a computed value such as
enableSystem={flag}.
Hook calls
UI-Theme returns theme, setTheme, resolvedTheme, systemTheme, and themes,
plus members that next-themes does not have. init accepts calls that use only
these five members.
Provider wrappers
Many apps wrap the provider in their own component. init supports one wrapper when
all of these are true:
- The component is a named export.
- It returns the provider and nothing else.
- Its only prop on the provider is
{...props}, spread from its own rest parameter.
init then maps the props at the one place where the app renders the wrapper.
When init stops
init stops for the cases below. Each message links to the section named here.
Provider shape
- A bare import, such as
import 'next-themes'. - A default or namespace import.
- No
ThemeProviderfromnext-themesin the app. For example, the app imports onlyuseTheme. - A second
ThemeProvider, or a second use of the wrapper. - A
ThemeProviderthat is conditional, or that appears outside JSX. - A wrapper with extra logic, a props spread other than the rest parameter, or an unnamed export.
- A file with a syntax error.
- A file that still contains the text
next-themesafter the rewrite, for example in a comment.
Provider props
- A prop that the prop mapping does not list.
- A computed prop value, or a props spread.
attributewith a value other thanclassordata-theme.- A missing
attributeorattribute="data-theme"outside Next.js. - A
defaultThemethat is notlight,dark, orsystem. themeswith a value other thanlightanddark.
useTheme
- An import other than
ThemeProvider,useTheme, orThemeProviderProps. - A use of
next-themesoutside a plain import:require, a dynamic import, a re-export, a mock, or a config file. - A member that UI-Theme does not return, such as
forcedTheme. - A function passed to
setTheme, or a theme other thanlight,dark, orsystem. - The whole result used as an object,
useThemeused as a value, or a call without an assignment.
Differences from next-themes
useThemeoutside a provider throws an error. Innext-themesversion 0.4.6, the hook returns an empty default object in the same case.- A theme is
light,dark, orsystem. For more looks, use color themes withcolorThemesandsetColorTheme. - UI-Theme has no
forcedThemeand novalueprop.setThemetakes a theme, not a function. - UI-Theme animates a theme change with
switchTheme.setThemechanges the theme at once. - The Next.js provider uses the
classattribute by default.next-themesusesdata-theme. - UI-Theme sets the
color-schemestyle on thehtmlelement itself.
shadcn provider
The shadcn dark mode guides for Vite and TanStack Start tell you to write
components/theme-provider.tsx by hand. init finds this file by its content,
not by its name. The TanStack Start version uses ScriptOnce.
With convert, init rewrites the file on top of UI-Theme:
ThemeProviderkeeps itsdefaultThemeandstorageKeyprops and their defaults. The saved preference stays where it was, for example undervite-ui-theme.useThemebecomesuseUITheme. It returnsthemeandsetThemewith the same meaning, so the files that call it do not change.- In Vite, the file wraps
UIThemeProvider. - In TanStack Start, the file wraps
TanStackUIThemeProviderand rendersTanStackStartThemeScriptin place ofScriptOnce.
init stops when the file exports more than ThemeProvider and useTheme, or when
the defaults are not plain strings. Then change the file by hand: follow the
manual setup and keep your storage key.
Upgrade
init upgrades a UI-Theme setup that does not fit the framework:
- A
UIThemeProviderorViteUIThemeProviderin a Next.js or TanStack Start app becomes the provider for that framework. Your local name stays the same. - A
theme-providerfile from an earlierinitthat you did not edit gets the current version. - In TanStack Start,
initadds the theme script to the document head. - In Next.js and TanStack Start,
initaddssuppressHydrationWarningto thehtmlelement.
Vite React accepts UIThemeProvider and ViteUIThemeProvider.
init asks you to finish the upgrade in these cases:
- You edited the
theme-providerfile.initkeeps your file. - The provider has a props spread, or
attributein TanStack Start. - A TanStack Start provider has no theme script. Add
TanStackStartThemeScriptwith the same options as the provider.
UI-Theme 1
init finds UI-Theme 1 when package.json lists @ui-theme/web or uitheme-vue,
or when a file imports them. Run the migration first, then run init again:
See Migrate to v2.
Other library
init does not run UI-Theme next to another theme library. Both would set the
dark class on the html element. init knows these libraries:
| Library | Frameworks |
|---|---|
@nuxtjs/color-mode | Nuxt |
useColorMode or useDark from @vueuse/core | Vue, Nuxt |
remix-themes | React |
use-dark-mode | React |
theme-change | Any |
mode-watcher | Any |
Remove the library, then run init again. You can also replace it by hand. See
the manual setup.
Custom provider
init reports a custom provider when a file has a theme name and a theme behavior.
- A name:
ThemeProvider,ThemeContext,ColorModeProvider,DarkModeProvider, or a file namedtheme-providerortheme-context. An inline script inindex.htmlalso counts. - A behavior: it sets the
darkorlightclass on the document, sets adata-themeattribute, stores a theme inlocalStorage, or readsprefers-color-scheme.
A ThemeProvider from a design system is not a theme setup. init ignores files
that import MUI, Chakra UI, Mantine, styled-components, Emotion, and similar
libraries. Those providers pass design tokens, not the page appearance.
init does not rewrite a custom provider. With alongside, it writes the
UI-Theme provider to components/ui-theme-provider.tsx as AppUIThemeProvider.
Swap your provider for it, then remove your own code.
Common patterns and what to change:
| Your code | What to change |
|---|---|
Context with a theme value and localStorage | Render the UI-Theme provider. Set storageKey to your key. Replace your hook with useUITheme. |
| A boolean dark mode | Use resolvedTheme === 'dark' to read it. Use setTheme('dark') and setTheme('light') to change it. A boolean stored as true is not a theme value, so the saved choice resets once. |
A data-theme attribute | In Next.js, set attribute="data-theme". In other frameworks, change your CSS to use the dark class. |
| A store with persistence, such as Zustand | Remove the theme from the store. Read and change it with useUITheme. |
| A cookie read on the server | In TanStack Start, use the cookie helpers in uitheme-web/tanstack. See the TanStack Start guide. |
CSS only, with prefers-color-scheme | Keep the media query or move it to the dark class. Set defaultTheme="system". |
| An inline script that sets the class | Remove it. The UI-Theme provider or theme script applies the class before the first paint. |
| Many palettes | Keep light and dark as the theme. Move each palette to a color theme with colorThemes. |
Manual setup
Use these steps after manual or alongside, or when init stops.
-
Install the runtime:
-
Import the provider for your framework:
Framework Provider Hook Import path Next.js NextUIThemeProvideruseNextUIThemeuitheme-web/nextTanStack Start TanStackUIThemeProvideruseTanStackUIThemeuitheme-web/reactVite React UIThemeProvideruseUIThemeuitheme-web/reactuseUIThemeworks under every React provider. The installed controls use it. -
Render the provider in place of your old provider. Use the prop mapping for
next-themesprops. -
In TanStack Start, add
TanStackStartThemeScriptto the document head. Use the same options as the provider. -
In Next.js and TanStack Start, add
suppressHydrationWarningto thehtmlelement. -
Replace each call of your old hook with the hook for your framework.
-
Test the first page load, a reload with a saved theme, and a change of the system appearance.
-
Remove the old package or code.
Use only one theme provider to control the appearance of the page at a time.

