@@ -6,18 +6,22 @@ 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 = { {
23+ __html : `(${ noFOUCScript . toString ( ) } )(${ [ k , t , n ] . map ( v => `'${ v } '` ) } )` ,
24+ } }
2125 nonce = { n }
2226 />
2327) ;
@@ -33,23 +37,6 @@ export interface CoreProps {
3337 k ?: string ;
3438}
3539
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-
5340/**
5441 * The Core component wich applies classes and transitions.
5542 * Cookies are set only if corresponding ServerTarget is detected.
@@ -61,10 +48,10 @@ const modifyTransition = (themeTransition = "none", nonce = "") => {
6148 *
6249 * @source - Source code
6350 */
64- export const Core = ( { t, nonce, k = "o" } : CoreProps ) => {
51+ export const Core = ( { t = "none" , nonce = "" , k = "o" } : CoreProps ) => {
6552 const isWindowDefined = typeof window != "undefined" ;
6653 // handle client side exceptions when script is not run. <- for client side apps like vite or CRA
67- if ( isWindowDefined && ! window . q ) noFOUCScript ( k ) ;
54+ if ( isWindowDefined && ! window . q ) noFOUCScript ( k , t , nonce ) ;
6855
6956 const [ { m, s } , setThemeState ] = useStore ( ) ;
7057
@@ -80,11 +67,7 @@ export const Core = ({ t, nonce, k = "o" }: CoreProps) => {
8067 e . key === k && setThemeState ( state => ( { ...state , m : e . newValue as ColorSchemePreference } ) ) ;
8168 } ) ;
8269 }
83- if ( updateDOM ) {
84- const restoreTransitions = modifyTransition ( t , nonce ) ;
85- updateDOM ( m , s ) ;
86- restoreTransitions ( ) ;
87- }
70+ updateDOM ?.( m , s ) ;
8871
89- return < Script { ...{ n : nonce , k } } /> ;
72+ return < Script { ...{ n : nonce , k, t } } /> ;
9073} ;
0 commit comments