Skip to content

Commit 8b37c84

Browse files
Improve rendering speed by moving settings generation after theme rendering
1 parent f10d199 commit 8b37c84

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

util/gh-pages/script.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,6 @@ function setTheme(theme, store) {
4646
}
4747
}
4848

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-
6049
window.searchState = {
6150
timeout: null,
6251
inputElem: document.getElementById("search-input"),
@@ -161,9 +150,6 @@ function handleShortcut(ev) {
161150
}
162151
}
163152

164-
document.addEventListener("keypress", handleShortcut);
165-
document.addEventListener("keydown", handleShortcut);
166-
167153
function toggleElements(filter, value) {
168154
let needsUpdate = false;
169155
let count = 0;
@@ -570,9 +556,6 @@ function generateSearch() {
570556
searchState.inputElem.addEventListener("paste", handleInputChanged);
571557
}
572558

573-
generateSettings();
574-
generateSearch();
575-
576559
function scrollToLint(lintId) {
577560
const target = document.getElementById(lintId);
578561
if (!target) {
@@ -617,7 +600,28 @@ function parseURLFilters() {
617600
}
618601
}
619602

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

Comments
 (0)