fix: resolve dark mode white flash on initial page load#7446
fix: resolve dark mode white flash on initial page load#7446AnkitRewar11 wants to merge 29 commits intolayer5io:masterfrom
Conversation
Refactor theme handling to use ThemeSetting values as keys and improve theme application logic. Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
@AnkitRewar11 Build is failing :( |
onRenderBody.js
Outdated
| export const onRenderBody = ( { setPreBodyComponents }) => { | ||
| export const onRenderBody = ({ setPreBodyComponents, setHtmlAttributes }) => { | ||
| // FIX 4: Set dark background at HTML level during SSR — before any JS runs | ||
| setHtmlAttributes({ style: "background-color: #000;" }); |
There was a problem hiding this comment.
@AnkitRewar11 Change to setHtmlAttributes({ style: { backgroundColor: "#000" } });
This can be root cause of build failure : )
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit 16be0d1 at: https://69a60abf69446feaf20b1156--layer5.netlify.app |
…hite flash Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit 4c00b0f at: https://69a6f5b69b91ec0965af033c--layer5.netlify.app |
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit e238605 at: https://69a6fc3180551b17ed94b78c--layer5.netlify.app |
Bhumikagarggg
left a comment
There was a problem hiding this comment.
please look it carefully it is still not working
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit dc10791 at: https://69a707bdb720f07b5a3f10e3--layer5.netlify.app |
|
@Bhumikagarggg Fixed FOUC properly by updating the onRenderBody.js script to set the background dynamically before hydration. Reverted isDark to false to avoid dark flashes for light mode users. Please review. |
@AnkitRewar11, are you aware that this specific link called netlify preview actually shows a site-preview for your changes ? after every commit you'll see this preview which carries chnages you made in your recent commits. so before requesting any review make sure everything is working in those specific netlify previews.. Thanks : ) |
|
@AnkitRewar11 and yes, i can still see white flash in latest preview :( |
Refactor theme handling logic and improve background color application. Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit cdd8e7d at: https://69a716e51f79b722326cbaca--layer5.netlify.app |
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit 8fd5caa at: https://69a71c097894c73d2fa21956--layer5.netlify.app |
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
Updated background colors for dark mode and light mode. Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit 9095d71 at: https://69abc061ed37728d8e011b33--layer5.netlify.app |
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit 63cb585 at: https://69abd59d900f7bca7380e519--layer5.netlify.app |
|
@YASHMAHAKAL @Bhumikagarggg I’ve pushed a fix for the FOUC issue by updating two files: onRenderBody.js (added Could you please check the Netlify preview when you get a chance? Thank you. 🙂 |
|
I’m not seeing the issue on the Netlify preview anymore from my side. Could you please check it once as well? 🙂 |
src/theme/app/ThemeManager.js
Outdated
|
|
||
| const defaultState = { | ||
| isDark: false, | ||
| isDark: true, // default dark |
There was a problem hiding this comment.
@AnkitRewar11 this is wrong, we do not want default dark mode.
|
@AnkitRewar11 please also remove all lint changes. Keep only logical changes |
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
Removed comments regarding theme handling logic. Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit 317d48d at: https://69ac0f36af6ad123b89386c5--layer5.netlify.app |
Removed comments and simplified theme object spread. Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit 0aca758 at: https://69ac2059911f6b445ccd334e--layer5.netlify.app |
src/theme/app/ThemeManager.js
Outdated
|
|
||
| export const ThemeManagerProvider = (props) => { | ||
| const [themeSetting, setThemeSetting] = useState(ThemeSetting.SYSTEM); | ||
| const [themeSetting, setThemeSetting] = useState(ThemeSetting.DARK); |
There was a problem hiding this comment.
@AnkitRewar11 keep it system. By default your settings it to dark.
|
@AnkitRewar11 Thank you for your contribution! Let's discuss this during the website call today at 6:30 PM IST | 7 AM CST Add it as an agenda item to the meeting minutes, if you would 🙂 |
|
Great effort tackling FOUC — the |
|
Nice work digging into the theme initialization flow! The CSS-first background fallback in |
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit 5b275bf at: https://69b25490c45136bccf8fdbf6--layer5.netlify.app |
|
🚀 Preview for commit a56ebe2 at: https://69b2584db34fb1e1f835c158--layer5.netlify.app |
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit f3c5dcf at: https://69b25eeaa53125de80717aba--layer5.netlify.app |
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit daea70b at: https://69b2649e420b0200773b520d--layer5.netlify.app |
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit c839a55 at: https://69b26bf4b34fb12d6735c27a--layer5.netlify.app |
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit 03365ec at: https://69b292579886c4ba6da04071--layer5.netlify.app |
Signed-off-by: Ankit Rewar <171806101+AnkitRewar11@users.noreply.github.com>
|
🚀 Preview for commit 624c764 at: https://69b29a9633f4feeb4339e3fd--layer5.netlify.app |
Description
This PR fixes #7443
Fixes the white background flash (FOUC) that appears
briefly before dark theme loads on initial page visit.
Changes Made
setHtmlAttributesto set dark background at HTML level during SSR before any JS runsNotes for Reviewers
Tested on initial page load — white flash no longer appears before dark theme loads.
Signed commits