@@ -6,18 +6,20 @@ let media: MediaQueryList,
66 updateDOM : ( mode : ColorSchemePreference , systemMode : ResolvedScheme ) => void ;
77
88interface ScriptProps {
9+ /** themeTransition */
10+ t : string ;
911 /** nonce */
10- n ? : string ;
12+ n : string ;
1113 /** storageKey */
1214 k : string ;
1315}
1416
1517/** Avoid rerender of script */
16- const Script = ( { n, k } : ScriptProps ) => (
18+ const Script = ( { n, k, t } : ScriptProps ) => (
1719 < script
1820 suppressHydrationWarning
1921 // skipcq: JS-0440
20- dangerouslySetInnerHTML = { { __html : `(${ noFOUCScript . toString ( ) } )('${ k } ')` } }
22+ dangerouslySetInnerHTML = { { __html : `(${ noFOUCScript . toString ( ) } )('${ [ k , t , n ] } ')` } }
2123 nonce = { n }
2224 />
2325) ;
@@ -33,23 +35,6 @@ export interface CoreProps {
3335 k ?: string ;
3436}
3537
36- /** Modify transition globally to avoid patched transitions */
37- const modifyTransition = ( themeTransition = "none" , nonce = "" ) => {
38- const doc = document ;
39- const css = doc . createElement ( "style" ) ;
40- /** split by ';' to prevent CSS injection */
41- css . textContent = `*,*:after,*:before{transition:${ themeTransition . split ( ";" ) [ 0 ] } !important;}` ;
42- css . setAttribute ( "nonce" , nonce ) ;
43- doc . head . appendChild ( css ) ;
44-
45- return ( ) => {
46- // Force restyle
47- getComputedStyle ( doc . body ) ;
48- // Wait for next tick before removing
49- setTimeout ( ( ) => doc . head . removeChild ( css ) , 1 ) ;
50- } ;
51- } ;
52-
5338/**
5439 * The Core component wich applies classes and transitions.
5540 * Cookies are set only if corresponding ServerTarget is detected.
@@ -61,10 +46,10 @@ const modifyTransition = (themeTransition = "none", nonce = "") => {
6146 *
6247 * @source - Source code
6348 */
64- export const Core = ( { t, nonce, k = "o" } : CoreProps ) => {
49+ export const Core = ( { t = "none" , nonce = "" , k = "o" } : CoreProps ) => {
6550 const isWindowDefined = typeof window != "undefined" ;
6651 // handle client side exceptions when script is not run. <- for client side apps like vite or CRA
67- if ( isWindowDefined && ! window . q ) noFOUCScript ( k ) ;
52+ if ( isWindowDefined && ! window . q ) noFOUCScript ( k , t , nonce ) ;
6853
6954 const [ { m, s } , setThemeState ] = useStore ( ) ;
7055
@@ -80,11 +65,7 @@ export const Core = ({ t, nonce, k = "o" }: CoreProps) => {
8065 e . key === k && setThemeState ( state => ( { ...state , m : e . newValue as ColorSchemePreference } ) ) ;
8166 } ) ;
8267 }
83- if ( updateDOM ) {
84- const restoreTransitions = modifyTransition ( t , nonce ) ;
85- updateDOM ( m , s ) ;
86- restoreTransitions ( ) ;
87- }
68+ updateDOM ?.( m , s ) ;
8869
89- return < Script { ...{ n : nonce , k } } /> ;
70+ return < Script { ...{ n : nonce , k, t } } /> ;
9071} ;
0 commit comments