Skip to content

Commit

Permalink
Disable CloudFlare Rocket loader on dark mode script (#1045)
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 authored Nov 6, 2022
1 parent 0a4894f commit 5aaf368
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
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 5aaf368

Please sign in to comment.