File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -26,12 +26,23 @@ export const isDark = computed<boolean>({
26
26
export const toggleDark = useToggle ( isDark )
27
27
28
28
if ( isClient ) {
29
+ const CSS_DISABLE_TRANS = '*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}'
30
+
29
31
watch (
30
32
isDark ,
31
33
( v ) => {
34
+ const style = window ! . document . createElement ( 'style' )
35
+ style . appendChild ( document . createTextNode ( CSS_DISABLE_TRANS ) )
36
+ window ! . document . head . appendChild ( style )
37
+
32
38
const html = document . querySelector ( 'html' ) !
33
39
html . classList . toggle ( 'dark' , v )
34
40
html . classList . toggle ( 'light' , ! v )
41
+
42
+ // Calling getComputedStyle forces the browser to redraw
43
+ // @ts -expect-error unused variable
44
+ const _ = window ! . getComputedStyle ( style ! ) . opacity
45
+ document . head . removeChild ( style ! )
35
46
} ,
36
47
{ immediate : true } ,
37
48
)
You can’t perform that action at this time.
0 commit comments