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 2 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
6 changes: 3 additions & 3 deletions docs/package.json
Expand Up @@ -10,12 +10,12 @@
"files": [],
"scripts": {
"images": "imagemin '_site/assets/images' --out-dir='_site/assets/images'",
"watch:sass": "sass --watch --poll src/assets/scss:src/assets/css",
"watch:sass": "sass --watch src/assets/scss:src/assets/css",
"watch:eleventy": "eleventy --serve --port=2023",
"build:sass": "sass --style=compressed src/assets/scss:src/assets/css --no-source-map",
"build:eleventy": "npx @11ty/eleventy",
"start": "npm-run-all build:sass --parallel watch:* --parallel images",
"build": "npm-run-all build:sass --parallel build:* --parallel images"
"start": "npm-run-all --parallel watch:* images",
"build": "npm-run-all --parallel build:* images"
harish-sethuraman marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@11ty/eleventy": "^1.0.1",
Expand Down
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