Repository navigation
Conversation
Owner
|
Thank you @fbartels , I tried this locally and the flash is gone, honestly that never bothered too much, but then I complain about the SAME issue when I'm at my phone and using dark theme, a new tab flashes and blinds me completely. 🤣 A few things would be nice if you can implenmet them before merging this PR though:
If you think you can do that in this PR then I'll wait to hear from you, otherwise I can merge this PR and tackle the pending things myself when I have some time. ;-) Thank you very much. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On every page load the app paints with the default (light) theme for a moment before the user's saved theme is applied — a visible flash on reload.
The cause: the theme CSS isn't present in
<head>.initTheme()runs during boot andapplyTheme()fetches/api/themes/<id>asynchronously, then injects<style id="dynamic-theme">. Until that round-trip completes, the first paint uses the base styles.Fix
Preload the saved theme synchronously in
<head>, before Alpine renders — the same pattern the file already uses for the locale preload just above it.localStorage['noteDiscoveryTheme']; if there's no saved preference it does nothing, so default-theme users are unaffected.data-themeand injects the CSS into a<style id="dynamic-theme">element.applyTheme()later reuses that same element, so nothing is applied twice.try/catch; on any error it falls back to the existing asyncapplyTheme()path.One file, one concern, no new dependencies.
Testing
darktheme.getComputedStyle(document.body).backgroundColorat the first animation frame:rgba(0, 0, 0, 0)(default) → finalrgb(31, 41, 55)(dark) — i.e. the flash.rgb(31, 41, 55)== finalrgb(31, 41, 55)— no flash.