Skip to content

fix: flash of white while loading page in dark mode on Firefox #4068

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Remove the deprecated `nodoc` option.
* Remove the deprecated `include-external` option.
* Refactor 404 error page to use div instead of p for search form.
* Fix the flash of white while loading pages in dark mode in Firefox.

## 8.3.4
* The URL for category pages now uses _category name_ instead of
Expand Down
5 changes: 3 additions & 2 deletions lib/resources/docs.dart.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/resources/docs.dart.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/resources/styles.css

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/src/generator/templates.aot_renderers_for_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,7 @@ String _deduplicated__head(TemplateDataBase context0) {
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
<meta name="color-scheme" content="light dark">
<meta name="description" content="''');
buffer.writeEscaped(context0.metaDescription);
buffer.write('''">
Expand Down Expand Up @@ -2476,7 +2477,7 @@ String _deduplicated__head(TemplateDataBase context0) {
buffer.write(context0.htmlBase);
buffer.write('''" data-using-base-href="''');
buffer.write(context0.useBaseHref.toString());
buffer.write('''" class="light-theme">
buffer.write('''" class="light-theme loading-theme">
<div id="overlay-under-drawer"></div>
<header id="title">
<span id="sidenav-left-toggle" class="material-symbols-outlined" role="button" tabindex="0">menu</span>
Expand Down
3 changes: 2 additions & 1 deletion lib/templates/_head.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
<meta name="color-scheme" content="light dark">
<meta name="description" content="{{ metaDescription }}">
<title>{{ title }}</title>
{{ #relCanonicalPrefix }}
Expand All @@ -30,7 +31,7 @@
</head>

{{! We don't use <base href>, but we do lookup the htmlBase from javascript. }}
<body data-base-href="{{{htmlBase}}}" data-using-base-href="{{{useBaseHref}}}" class="light-theme">
<body data-base-href="{{{htmlBase}}}" data-using-base-href="{{{useBaseHref}}}" class="light-theme loading-theme">

<div id="overlay-under-drawer"></div>

Expand Down
2 changes: 1 addition & 1 deletion web/sig.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
76460F3B17D947F654BCE4B231EBE30F
8B61A9700A910E857DB14C88C8B399DC
11 changes: 11 additions & 0 deletions web/styles/_theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@
}
}

.loading-theme {
// Until the light-mode or dark-mode class is applied to the body,
// this class tells the browser to use the system theme's lightness.
// This prevents a white flash while the page is loading.
color-scheme: light dark;
background: initial;
color: initial;
--main-bg-color: initial;
--main-header-color: initial;
}

#theme-button {
// Reset button appearance.
appearance: none;
Expand Down
5 changes: 5 additions & 0 deletions web/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ void init() {

window.localStorage.setItem('colorTheme', 'false');
}

bodyElement.classList.remove('loading-theme');
}

themeButton.addEventListener(
Expand All @@ -39,5 +41,8 @@ void init() {

if (window.localStorage.getItem('colorTheme') case var colorTheme?) {
switchThemes(colorTheme == 'true');
} else {
// Default to light mode.
switchThemes(false);
}
}