@@ -46,17 +46,6 @@ function setTheme(theme, store) {
46
46
}
47
47
}
48
48
49
- // loading the theme after the initial load
50
- const prefersDark = window . matchMedia ( "(prefers-color-scheme: dark)" ) ;
51
- const theme = loadValue ( 'theme' ) ;
52
- if ( prefersDark . matches && ! theme ) {
53
- setTheme ( "coal" , false ) ;
54
- } else {
55
- setTheme ( theme , false ) ;
56
- }
57
- let disableShortcuts = loadValue ( 'disable-shortcuts' ) === "true" ;
58
- document . getElementById ( "disable-shortcuts" ) . checked = disableShortcuts ;
59
-
60
49
window . searchState = {
61
50
timeout : null ,
62
51
inputElem : document . getElementById ( "search-input" ) ,
@@ -161,9 +150,6 @@ function handleShortcut(ev) {
161
150
}
162
151
}
163
152
164
- document . addEventListener ( "keypress" , handleShortcut ) ;
165
- document . addEventListener ( "keydown" , handleShortcut ) ;
166
-
167
153
function toggleElements ( filter , value ) {
168
154
let needsUpdate = false ;
169
155
let count = 0 ;
@@ -570,9 +556,6 @@ function generateSearch() {
570
556
searchState . inputElem . addEventListener ( "paste" , handleInputChanged ) ;
571
557
}
572
558
573
- generateSettings ( ) ;
574
- generateSearch ( ) ;
575
-
576
559
function scrollToLint ( lintId ) {
577
560
const target = document . getElementById ( lintId ) ;
578
561
if ( ! target ) {
@@ -617,7 +600,28 @@ function parseURLFilters() {
617
600
}
618
601
}
619
602
620
- parseURLFilters ( ) ;
621
- scrollToLintByURL ( ) ;
622
- filters . filterLints ( ) ;
623
- onEachLazy ( document . querySelectorAll ( "pre > code.language-rust" ) , el => hljs . highlightElement ( el ) ) ;
603
+ // loading the theme after the initial load
604
+ const prefersDark = window . matchMedia ( "(prefers-color-scheme: dark)" ) ;
605
+ const theme = loadValue ( 'theme' ) ;
606
+ if ( prefersDark . matches && ! theme ) {
607
+ setTheme ( "coal" , false ) ;
608
+ } else {
609
+ setTheme ( theme , false ) ;
610
+ }
611
+
612
+ let disableShortcuts = loadValue ( 'disable-shortcuts' ) === "true" ;
613
+ // To prevent having a "flash", we give back time to the web browser to finish rendering with
614
+ // theme applied before finishing the rendering.
615
+ setTimeout ( ( ) => {
616
+ document . getElementById ( "disable-shortcuts" ) . checked = disableShortcuts ;
617
+
618
+ document . addEventListener ( "keypress" , handleShortcut ) ;
619
+ document . addEventListener ( "keydown" , handleShortcut ) ;
620
+
621
+ generateSettings ( ) ;
622
+ generateSearch ( ) ;
623
+ parseURLFilters ( ) ;
624
+ scrollToLintByURL ( ) ;
625
+ filters . filterLints ( ) ;
626
+ onEachLazy ( document . querySelectorAll ( "pre > code.language-rust" ) , el => hljs . highlightElement ( el ) ) ;
627
+ } , 0 ) ;
0 commit comments