-
Notifications
You must be signed in to change notification settings - Fork 163
fix: flash of white while loading page in dark mode on Firefox #8836
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
base: master
Are you sure you want to change the base?
Conversation
The dark mode theme and color is controlled via a CSS variable that is set after the site's JavaScript is being loaded. I don't see how this would reduce any flash of white - could you please provide more details on how this would change any of the behavior? E.g. what is the benefit here instead e.g. styling the |
When the browser starts loading the page, it loads the html first before the css. So having the color-scheme defined in the html means the browser can apply a dark background sooner, instead of having to wait for the css to load. https://developer.mozilla.org/en-US/docs/Web/CSS/color-scheme:
The majority of users will probably use the same theme as their system, so the color-scheme tag works for this. |
Upon closer inspection, I see a difference between pub.dev and As a follow-up change, we should also support media selectors, and after that, we should consider if/how the feature should work with non-blocking rendering. I wouldn't mind having the metadata here on the page (after the above changes), but I don't think it will help for those who leave their OS theme settings on default but switch their theme on pub.dev. |
Hmm yes I see the issue. When the page is first loaded, it's served with pub-dev/app/lib/frontend/templates/views/shared/layout.dart Lines 179 to 185 in f4cf87f
In Chrome, this seems to work fine as the js blocks the rest of the document from getting parsed & rendered. I've added I've then added a temporary Note:
|
Perhaps a better solution long-term is to initially load the body without // <meta name="color-scheme" content="light dark"/>
body.light-theme { color-scheme: light; }
body.dark-theme { color-scheme: dark; }
body {
--pub-neutral-bgColor: light-dark(var(--pub-color-white), var(--pub-color-darkBlack));
--pub-neutral-borderColor: light-dark(var(--pub-color-smokeWhite), var(--pub-color-darkGunmetal));
--pub-neutral-textColor: var(--dash-surface-fgColor);
// etc
} By default, this will use the system theme. Then the script can add |
@adil192 I'm more comfortable with a very narrow fix that I've implemented in #8837, and I suggest we close this PR. An important reason for that is we have some plans to bring the dartdoc and pub.dev styles and layout closer, and while those plans are still in progress, I wouldn't want to change too much things all at once. However, I think we should keep track of the suggestions you were making here - would you mind creating an issue or two about them, describing why the metadata or anything else would be important (if it still is after a fix)? |
Upon further reading about the I'm a bit undecided whether the |
<meta name="color-scheme" content="light dark"/>
so the browser's default dark mode can be applied before the css is loaded (https://web.dev/articles/color-scheme)color-scheme: dark;
orlight
as needed.(I'm unsure if the pubspec package version needs increasing)
Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.