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:
@@ -0,0 +1,6 @@
|
||||
<%= javascript_tag nonce: true do %>
|
||||
const theme = localStorage.getItem("theme")
|
||||
if (theme && theme !== "auto") {
|
||||
document.documentElement.dataset.theme = theme
|
||||
}
|
||||
<% end %>
|
||||
@@ -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 %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user