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

Prevent screen flash on page load #3

Merged
merged 1 commit into from
Sep 14, 2023
Merged

Conversation

colegoldsmith
Copy link
Collaborator

This attempts to fix the "flash" that happens when you first load the site with the dark theme. Initially the light theme is default so the screen shows light colors for a split second before switching to dark.

This change solves the flash problem for most of the states on page load, but potentially not when the system preference and local storage setting differ.

  • Prefers light mode + no local storage setting: No flash
  • Prefers dark mode + no local storage setting: No flash
  • Prefers light mode + light mode local storage: No flash
  • Prefers dark mode + dark mode local storage: No flash
  • Prefers light mode + dark mode local storage: Sometimes a flash
  • Prefers dark mode + light mode local storage: Sometimes a flash

How to test

  1. Run the UI in preview or as the bundle for a docs project
  2. Refresh the page after setting one or both of the settings: prefers-color-scheme and local storage

I found this helpful in chrome to manually change the prefers-color-scheme
Screenshot 2023-09-13 at 10 48 29 AM

To change local storage you can press the theme switch button, do delete you can remove from here
Screenshot 2023-09-13 at 10 53 26 AM

@colegoldsmith colegoldsmith merged commit 11eabed into main Sep 14, 2023
@colegoldsmith colegoldsmith deleted the theme-flicker-fix branch September 14, 2023 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant