29 lines
818 B
TypeScript
29 lines
818 B
TypeScript
'use client'
|
|
|
|
import * as React from 'react'
|
|
import {
|
|
ThemeProvider as NextThemesProvider,
|
|
type ThemeProviderProps,
|
|
} from 'next-themes'
|
|
|
|
export function ThemeProvider({
|
|
children,
|
|
scriptProps,
|
|
...props
|
|
}: ThemeProviderProps) {
|
|
// next-themes renders an inline <script> to prevent theme flicker.
|
|
// React 19 warns about script tags inside client components on hydration.
|
|
// SSR keeps the default executable script; the client uses a non-executable
|
|
// type so React does not warn (the blocking script already ran from HTML).
|
|
const resolvedScriptProps =
|
|
typeof window === 'undefined'
|
|
? scriptProps
|
|
: { ...scriptProps, type: 'application/json' as const }
|
|
|
|
return (
|
|
<NextThemesProvider {...props} scriptProps={resolvedScriptProps}>
|
|
{children}
|
|
</NextThemesProvider>
|
|
)
|
|
}
|