Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: avoid theme flashes #15927

Merged
merged 3 commits into from Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/src/_includes/layouts/base.njk
Expand Up @@ -46,13 +46,13 @@
<link rel="preload" href="{{ '/assets/fonts/SpaceMono-Regular-subset.woff2' | url }}" as="font" type="font/woff2" crossorigin>

<script>
(function(){
var theme = window.localStorage.getItem("theme");
if (!theme && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.setAttribute('data-theme', 'dark');
}
else if (theme) document.documentElement.setAttribute('data-theme', theme);
})();
(function () {
var theme = window.localStorage.getItem("theme");
if (theme) document.documentElement.setAttribute('data-theme', theme)
else if (window.matchMedia('(prefers-color-scheme: dark)').matches)
document.documentElement.setAttribute('data-theme', 'dark');
else document.documentElement.setAttribute('data-theme', 'light');
})();
</script>


Expand Down
9 changes: 0 additions & 9 deletions docs/src/assets/js/themes.js
Expand Up @@ -8,11 +8,6 @@
btn.setAttribute("aria-pressed", "false");
}


let theme = window.localStorage.getItem("theme");
document.documentElement.setAttribute('data-theme', theme);
if (!theme) document.documentElement.setAttribute('data-theme', 'light');

harish-sethuraman marked this conversation as resolved.
Show resolved Hide resolved
document.addEventListener('DOMContentLoaded', function() {
var switcher = document.getElementById('js-theme-switcher');
switcher.removeAttribute('hidden');
Expand All @@ -22,10 +17,6 @@

// get any previously-chosen themes
var theme = window.localStorage.getItem("theme");
if (!theme && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.setAttribute('data-theme', 'dark');
}
else if (theme) document.documentElement.setAttribute('data-theme', theme);

if (theme == "light") {
enableToggle(light_theme_toggle);
Expand Down