Apply theme preference before body

To avoid any visual flashes of the old theme before the Stimulus
controllers load, we can apply the saved theme from `<head>` whenever
there is a full page load.

This applies to both the regular and public views, as we're doing it in
the shared head partial.
This commit is contained in:
Kevin McConnell
2025-12-12 14:17:58 +00:00
parent 2a17976f9c
commit 87ad234f32
2 changed files with 7 additions and 0 deletions
@@ -0,0 +1,6 @@
<%= javascript_tag nonce: true do %>
const theme = localStorage.getItem("theme")
if (theme && theme !== "auto") {
document.documentElement.dataset.theme = theme
}
<% end %>
+1
View File
@@ -15,6 +15,7 @@
<% turbo_refreshes_with method: :morph, scroll: :preserve %>
<%= render "layouts/theme_preference" %>
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>