next-themes
next-themes copied to clipboard
attribute="class" causing the following error with Tailwindcss and nextjs
It's working only with ThemeProvider
but not working with attribute="class"
<ThemeProvider attribute="class">
<Component {...pageProps} />
</ThemeProvider>
InvalidCharacterError: Failed to execute 'add' on 'DOMTokenList': The token provided ('[object Object]') contains HTML space characters, which are not valid in tokens.
I have had this happen too, but only when the class I specify for the theme has spaces in it. To be specific that means I had a value
of {light: 'classA classB'}
I don't know of a way to specify two classes for a theme 😕. But hopefully this helps you debug.
I only noticed this happening when providing a function to the setTheme
function.
e.g
setTheme((prev) => prev === 'dark' ? 'light' : 'dark')
This sets the function as a string to LocalStorage. Not sure if you're seeing the issue for this reason.
I got this while working in NextJs 13
@684efs3 How were you able to get this working in Nextjs version 13? Are you using the App directory?
same problem here using appDir
Please, I will like to know if someone found a work around on this issue.
I only noticed this happening when providing a function to the
setTheme
function.e.g
setTheme((prev) => prev === 'dark' ? 'light' : 'dark')
This sets the function as a string to LocalStorage. Not sure if you're seeing the issue for this reason.
I have removed the setTheme, updated next to @latest, and deleted the node modules and reinstall but still the same issue
Hey, has anyone here got an update about this issue? I am using Next.js 13 with appdir, thanks in advance!
I fixed this on Next.js 14 by doing the following
- In Chrome Developer Tools, go to Application > Local Storage > delete the
theme
variable - Change
<button onClick={ () => { setTheme((prev) => prev === 'dark' ? 'light' : 'dark') } }>
change mode
</button>
to
<button onClick={ theme === "light" ? () => { setTheme("dark") } : () => { setTheme("light") } }>
change mode
</button>
(Not 100% sure if step 2 is necessary, but it worked for me.)
This issue still persists for both nextjs13 and 14 . anyone got it working yet ?
- In Chrome Developer Tools, go to Application > Local Storage > delete the
theme
variable
This worked for me, step 2 wasn't necessary.
- In Chrome Developer Tools, go to Application > Local Storage > delete the
theme
variable
This worked for me, step 2 wasn't necessary.
I was working in other project using chakra ui theme, so i think this is causing a conflict.