theme: Move initColorScheme() to head

This should reduce the amount of blocking JS.

Also remove the initColorScheme() in `turbo:render` which is not needed after we moved the `dark` class from body to documentElement.
This commit is contained in:
Bjørn Erik Pedersen
2025-09-17 16:02:32 +02:00
parent a1566495bf
commit 98e9ef5f0c
4 changed files with 4 additions and 17 deletions
-6
View File
@@ -1,6 +0,0 @@
import { initColorScheme } from './alpinejs/stores/index';
(function () {
// This allows us to initialize the color scheme before AlpineJS etc. is loaded.
initColorScheme();
})();
+4
View File
@@ -1,6 +1,10 @@
import { scrollToActive } from 'js/helpers/index';
import { initColorScheme } from './alpinejs/stores/index';
(function () {
// This allows us to initialize the color scheme before AlpineJS etc. is loaded.
initColorScheme();
// Now we know that the browser has JS enabled.
document.documentElement.classList.remove('no-js');
-8
View File
@@ -8,14 +8,6 @@ import focus from '@alpinejs/focus';
var debug = 0 ? console.log.bind(console, '[index]') : function () {};
// Turbolinks init.
(function () {
document.addEventListener('turbo:render', function (e) {
// This is also called right after the body start. This is added to prevent flicker on navigation.
initColorScheme();
});
})();
// Set up and start Alpine.
(function () {
// Register AlpineJS plugins.
@@ -1,3 +0,0 @@
{{ with resources.Get "js/body-start.js" | js.Build (dict "minify" true) }}
{{ partial "helpers/linkjs.html" (dict "r" . "attributes" (dict "" "")) }}
{{ end }}