Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Fix flashing on reapplying theme (#3760)

hq19f2f89442108
diff --git a/lib/plausible_web/components/layout.ex b/lib/plausible_web/components/layout.ex
index 8dac6c784a..2665f3bef3 100644
--- a/lib/plausible_web/components/layout.ex
+++ b/lib/plausible_web/components/layout.ex
@@ -5,7 +5,7 @@ defmodule PlausibleWeb.Components.Layout do
def theme_script(assigns) do
~H"""
- <script>
+ <script blocking="rendering">
(function(){
var themePref = '<%= theme_preference(assigns) %>';
function reapplyTheme() {
diff --git a/lib/plausible_web/templates/layout/app.html.heex b/lib/plausible_web/templates/layout/app.html.heex
index 985251d854..ee6841c409 100644
--- a/lib/plausible_web/templates/layout/app.html.heex
+++ b/lib/plausible_web/templates/layout/app.html.heex
@@ -25,6 +25,7 @@
"Plausible · Simple, privacy-friendly alternative to Google Analytics" %>
</title>
<link rel="stylesheet" href={Routes.static_path(@conn, "/css/app.css")} />
+ <PlausibleWeb.Components.Layout.theme_script {Map.take(assigns, [:current_user, :theme])} />
<%= render("_tracking.html", assigns) %>
</head>
<body
@@ -45,8 +46,6 @@
<%= Map.get(assigns, :inner_layout) || @inner_content %>
</main>
- <PlausibleWeb.Components.Layout.theme_script {Map.take(assigns, [:current_user, :theme])} />
-
<%= if assigns[:embedded] do %>
<div data-iframe-height></div>
<script type="text/javascript" src={Routes.static_path(@conn, "/js/embed.content.js")}>