Skip to content

Commit 7678743

Browse files
committed
theme: Misc color scheme loading improvements
* Avoid calling initColorScheme() on navigation. It's not needed anymore after we moved the dark class to the document element. * Move initColorScheme() to body end. Avoids blocking, seem to work as well preventing flickering on load.
1 parent a156649 commit 7678743

File tree

5 files changed

+8
-12
lines changed

5 files changed

+8
-12
lines changed

‎assets/js/alpinejs/stores/nav.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ function isDark(colorScheme) {
7474
}
7575

7676
export function initColorScheme() {
77+
if (window.colorSchemeInitialized) {
78+
return;
79+
}
80+
window.colorSchemeInitialized = true;
7781
// The AlpineJS store has not have been initialized yet, so access the
7882
// localStorage directly.
7983
let settingsJSON = localStorage[localStorageUserSettingsKey];
File renamed without changes.

‎assets/js/main.js‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import Alpine from 'alpinejs';
22
import { registerMagics } from './alpinejs/magics/index';
33
import { navbar, search, toc } from './alpinejs/data/index';
4-
import { navStore, initColorScheme } from './alpinejs/stores/index';
4+
import { navStore } from './alpinejs/stores/index';
55
import { bridgeTurboAndAlpine } from './helpers/index';
66
import persist from '@alpinejs/persist';
77
import focus from '@alpinejs/focus';
88

99
var debug = 0 ? console.log.bind(console, '[index]') : function () {};
1010

11-
// Turbolinks init.
12-
(function () {
13-
document.addEventListener('turbo:render', function (e) {
14-
// This is also called right after the body start. This is added to prevent flicker on navigation.
15-
initColorScheme();
16-
});
17-
})();
18-
1911
// Set up and start Alpine.
2012
(function () {
2113
// Register AlpineJS plugins.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{{ with resources.Get "js/body-end.js" | js.Build (dict "minify" true) }}
2+
{{ partial "helpers/linkjs.html" (dict "r" . "attributes" (dict "" "")) }}
3+
{{ end }}
14
{{- if .IsHome }}
25
{{- partial "helpers/validation/validate-keywords.html" }}
36
{{- end }}
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
{{ with resources.Get "js/body-start.js" | js.Build (dict "minify" true) }}
2-
{{ partial "helpers/linkjs.html" (dict "r" . "attributes" (dict "" "")) }}
3-
{{ end }}

0 commit comments

Comments
 (0)