question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Flash of color" when using outside theme that depends on theme-ui

See original GitHub issue

Summary

When using gatsby-theme-docz which depends on theme-ui, I’m noticing a “flash of color” issue when switching to dark mode (light mode is first rendered). This seems to be a known issue that can be resolved by installing gatsby-plugin-theme-ui (maybe?) but I wasn’t sure how this would work if I am relying on an intermediary theme, in this case gatsby-theme-docz.

I’ve posted this issue here and in docz - I hope that’s okay!


Bug Report

When initialColorConfig is set to light (default), switching to dark mode using gatsby-theme-docz will cause the “light mode” to initially flicker on any page render. Not sure if this is a docz, gatsby, or theme-ui issue, so I may just post this everywhere. 😅

To Reproduce

Set up a repo with instructions from Gatsby site. You also need to npm i docz@next which isn’t mentioned. Run gatsby develop and toggle the color mode using the icon to view the site in “dark mode.”

Now navigate to a different page, and you should see the light mode flicker before the dark theme is applied. Switching initialColorConfig to dark will cause the dark theme to flicker when switching to light mode.

Sample repo: https://github.com/Yihwan/gatsby-docz-flicker-issue

Though not necessary to reproduce the bug, you may also want to pull in the src folder of gatsby-theme-docz into your src/gatsby-theme-docs dir to debug further. This has already been done in the sample repo.

NB: Since useColorConfig utilizes localStorage, you may have to clear site application data as needed or use incognito.

Debugging so far

Best I can tell, this has to do with the site not picking up on the selected theme-ui-color-mode in localStorage on first render. Instead, for some reason the initialColorConfig selection is rendered first.

This seems to be a known issue with theme-ui because I found at least a passing reference to the issue in the docs. Not sure how this will git in with gatsby-theme-docz though.

Thank you in advance!!!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
hasparuscommented, Mar 29, 2021

Hey folks, just FYI this should be fixed with 0.6.0 — If all of your colors are in the theme object, their CSS properties should be updated on page load. Let me know if you still experience the issue after updating.

1reaction
jxnblkcommented, Dec 10, 2019

I’ll have to look into this later, but I think Docz should be using gatsby-plugin-theme-ui to handle this, and as a user of gatsby-theme-docz, you shouldn’t have to install the Theme UI plugin separately. That said, there could definitely be a bug somewhere, which would be causing the flash of colors

Read more comments on GitHub >

github_iconTop Results From Across the Web

Color Modes - Theme UI
Color Modes. Color modes can be used to create a user-configurable dark mode or any number of other color modes. Defining colors. In...
Read more >
Easy Dark Mode (and Multiple Color Themes!) in React
This guide assumes a basic familiarity with CSS, JavaScript, and React. First, make sure you have a recent version of Node and npm...
Read more >
Dark mode | NextUI - Beautiful, fast and modern React UI Library
NextUI comes with two palette modes light (the default) and dark, as we mentioned before. you can make the theme dark by setting...
Read more >
prefers-color-scheme - CSS: Cascading Style Sheets | MDN
The prefers-color-scheme CSS media feature is used to detect if a user has requested light or dark color themes.
Read more >
How to get a flickerless persistent dark mode in your Next.js ...
Note that this tutorial is made with Material UI, but will work with most other UI libraries ... and update our _app.tsx with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found