Skip to content

Commit

Permalink
Fix RatanShreshtha#46 : Dark mode flickers on load of new page
Browse files Browse the repository at this point in the history
For this, I moved the theme attribute from body to the html tag
  • Loading branch information
Pierre Galvez committed May 21, 2022
1 parent a96aab8 commit 6e7ea36
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions sass/deep-thought.sass
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ $family-sans-serif: "Jost", sans-serif;
$footer-padding: 1.0rem 2.5rem;

@mixin base_dark
filter: invert(1) hue-rotate(180deg);

body,
img,
picture,
video,
Expand All @@ -26,11 +25,11 @@ body
min-height: 100vh;


body[theme="dark"]
html[theme="dark"]
@include base_dark()


body[theme="auto"]
html[theme="auto"]
@media (prefers-color-scheme: dark)
@include base_dark()

Expand Down
4 changes: 2 additions & 2 deletions static/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function search() {
}

function setTheme(color) {
document.body.setAttribute("theme", color);
document.documentElement.setAttribute("theme", color);
document.getElementById("dark-mode").setAttribute("title", "Switch to "+color+" theme");
}

Expand Down Expand Up @@ -219,7 +219,7 @@ function documentReadyCallback() {
});

document.getElementById("dark-mode").addEventListener("click", () => {
const theme = document.body.getAttribute("theme");
const theme = document.documentElement.getAttribute("theme");
const isDarkMode = window.matchMedia("(prefers-color-scheme: dark)").matches;
if (
theme === "light" || theme === null || (theme === "auto" && !isDarkMode)
Expand Down

0 comments on commit 6e7ea36

Please sign in to comment.