Skip to content

Commit

Permalink
Disable CloudFlare Rocket loader on dark mode script
Browse files Browse the repository at this point in the history
If it's enabled, then the initialization of the dark mode does not occur
early enough, and the page will flash from light-to-dark if that was the
saved theme.

See the CloudFlare documentation for details:
https://support.cloudflare.com/hc/en-us/articles/200168056-Understanding-Rocket-Loader
  • Loading branch information
QuLogic committed Nov 5, 2022
1 parent 0a4894f commit b2a06dc
Showing 1 changed file with 4 additions and 1 deletion.
Expand Up @@ -27,7 +27,10 @@
or not theme_secondary_sidebar_items %}

{%- block css %}
<script>
{# The data-cfasync attribute disables CloudFlare's Rocket loader so that #}
{# mode/theme are correctly set before the browser renders the page. #}
{# https://github.com/pydata/pydata-sphinx-theme/pull/1045 #}
<script data-cfasync="false">
document.documentElement.dataset.mode = localStorage.getItem("mode") || "{{ default_mode }}";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "light";
</script>
Expand Down

0 comments on commit b2a06dc

Please sign in to comment.