Skip to content

fix: eliminate dark mode Flash of Unstyled Content (FOUC)#8180

Open
ryzrr wants to merge 2 commits intowebpack:mainfrom
ryzrr:fix/dark-mode-fouc
Open

fix: eliminate dark mode Flash of Unstyled Content (FOUC)#8180
ryzrr wants to merge 2 commits intowebpack:mainfrom
ryzrr:fix/dark-mode-fouc

Conversation

@ryzrr
Copy link
Copy Markdown
Contributor

@ryzrr ryzrr commented Apr 9, 2026

Summary
Fixes the dark mode flash on page load by injecting a very short blocking script into the HTML head.

What kind of change does this PR introduce?
Bug fix

Did you add tests for your changes?
No, but existing tests were run to ensure nothing broke.

Does this PR introduce a breaking change?
No.

If relevant, what needs to be documented once your changes are merged or what have you already documented?
Nothing needs to be documented.

Use of AI?
No

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
webpack-js-org Ready Ready Preview, Comment Apr 9, 2026 6:05pm

Request Review

} catch (e) {}
})();
</script>
</head>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we fix it without such code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the inline script is the most reliable way to avoid flash 'cause it handles both the system theme and the users saved preference. BUT, another option is using CSS with prefers-color-scheme, which covers the OS setting without any script.

The trade off is that if the user has chosen a different theme than the OS, there might be a brief flash until React loads.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the inline script is the most reliable way to avoid flash 'cause it handles both the system theme and the users saved preference. BUT, another option is using CSS with prefers-color-scheme, which covers the OS setting without any script.

I think it is a good choose

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented the CSS-only route , but it creates a reversed flash for users who override their OS theme preference.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This , CSS-only approach works for most users, but if someone's OS is set to dark but they've manually picked light mode on the site (or vice versa), they still see a brief flash. So we've just moved the problem. Let me know how you'd like me to proceed.

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.

2 participants