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

White flash on page refresh with dark theme #441

Open
julienduchesne opened this issue Oct 17, 2020 · 7 comments
Open

White flash on page refresh with dark theme #441

julienduchesne opened this issue Oct 17, 2020 · 7 comments

Comments

@julienduchesne
Copy link

Hi, when refreshing a page or loading a new one with the dark theme, I get a white "flash" everytime. Seems like the page goes white while the dark theme is loading.

Is this only happening to me?

Does anyone have a solution for this or is it something that would need to be fixed in the template?

As an example, it happens when I click the user name in the demo website: https://hugo-coder.netlify.app/

@clement-pannetier
Copy link
Contributor

Hi @julienduchesne, as you can see here #350 in my comment, I said : "Just a quick note, you're maybe going to experience FOUC problems when switching themes.".
That's a thing I tried to fix without success and forget about.
If you have a solution, I will be quite interested.

@luizdepra
Copy link
Owner

I need to confess that I never saw this issue happening. Which browser do you guys use?

@clement-pannetier
Copy link
Contributor

I'm using brave but I think it's not related to the browser. Here is a gif showing the flash I get sometimes:
flash-on-page-refresh

@pduchnovsky
Copy link
Contributor

pduchnovsky commented Nov 8, 2020

can confirm this is happening, tested on chrome/edge chromium, both experience the same, it practically makes mode switch unusable tbh :(
It happens when your system reports preferred mode Dark and you switch and use light theme ... and vice versa, if your system reports light but you switch to and use dark, same issue.

@pduchnovsky
Copy link
Contributor

pduchnovsky commented Nov 10, 2020

When I enable 'Bundle JS' feature of Netlify in Site Postprocessing - Asset Optimization, this problem is gone though.

Edit: Found the problem..
This is without netlify optimization:
image
This is with..:
image

The problem is max-age=0 for dark mode script by default.. while netlify optimization basically creates a new file and sets max-age to actually acceptable value.
Therefore problem is that by default some hosting providers don't allow caching of the scripts, therefore it downloads it on every refresh, causing delay in applying white/dark mode.

It could be a solution to move this script inline
Edit: Already included fix in my PR #481

@Esgariot
Copy link

Esgariot commented Jan 28, 2021

Does it have anything to do with /posts/ into /post/ url redirection?

https://themes.gohugo.io//theme/hugo-coder/post/ look at url when pressing "Blog"

@luizdepra
Copy link
Owner

@Esgariot, I think this is the first time I've seen the flash on Firefox. But, this case looks like something different. We can easily fix it removing the redirect.

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

No branches or pull requests

5 participants