Skip to content

fix: resolve flash of unstyled content in dark mode#766

Merged
avivkeller merged 1 commit into
nodejs:mainfrom
TusharThakur04:fix/dark-mode-FOUC
Jun 16, 2026
Merged

fix: resolve flash of unstyled content in dark mode#766
avivkeller merged 1 commit into
nodejs:mainfrom
TusharThakur04:fix/dark-mode-FOUC

Conversation

@TusharThakur04

Copy link
Copy Markdown
Contributor

Description

This PR resolves the FOUC by resolving system to dark or light using matchMedia.
Earlier system was directly being applied as set-theme = system

Validation

before :

Screencast.from.2026-04-13.19-26-34.webm

after :

Screencast.from.2026-04-13.19-24-03.webm

Related Issues

n/a

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run node --run test and all tests passed.
  • I have check code formatting with node --run format & node --run lint.
  • I've covered new added functionality with unit tests if necessary.

@TusharThakur04 TusharThakur04 requested a review from a team as a code owner April 13, 2026 14:23
@cursor

cursor Bot commented Apr 13, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Low risk: changes are limited to how the initial data-theme is computed and inlined before first paint; main risk is edge-case behavior differences for users with stored theme preferences.

Overview
Fixes initial-page theme application to avoid dark-mode Flash of Unstyled Content by replacing the hardcoded inline snippet with an injected themeScript.

Adds ui/theme-script.mjs, which resolves the stored theme preference (including system) to a concrete dark/light value via matchMedia and applies it to documentElement before render; processing.mjs now passes this script into template.html for inlining.

Reviewed by Cursor Bugbot for commit ae47eff. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Apr 13, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview Apr 25, 2026 5:43pm

Request Review

Comment thread src/generators/web/template.html Outdated
Comment thread src/generators/web/template.html Outdated
@avivkeller

Copy link
Copy Markdown
Member

This seems highly complex

@TusharThakur04

Copy link
Copy Markdown
Contributor Author

the {$themeScript} literal is being replaced by newly created themeScript by generate.mjs

it is done so that the script is available before rendering the html and there is no latency which could have happened if browser makes request for the themeScript.mjs if we use src inside the script tag

Comment thread src/generators/web/generate.mjs Outdated
Comment thread src/generators/web/template.html Outdated
Comment thread src/generators/web/template.html Outdated
Comment thread src/generators/web/generate.mjs Outdated
@codecov

codecov Bot commented Apr 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.94%. Comparing base (3d00fa8) to head (ae47eff).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
src/generators/web/utils/processing.mjs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #766      +/-   ##
==========================================
- Coverage   78.43%   77.94%   -0.49%     
==========================================
  Files         157      159       +2     
  Lines       13962    14058      +96     
  Branches     1152     1152              
==========================================
+ Hits        10951    10958       +7     
- Misses       3006     3095      +89     
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/generators/web/utils/processing.mjs Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3c1f1be. Configure here.

Comment thread src/generators/web/ui/theme-script.mjs Outdated
@TusharThakur04

Copy link
Copy Markdown
Contributor Author

@ovflowd
please review, i ve made the changes you suggested

Comment thread src/generators/web/ui/theme-script.mjs Outdated
Comment thread src/generators/web/ui/theme-script.mjs Outdated
Comment thread src/generators/web/ui/theme-script.mjs Outdated

@canerakdas canerakdas left a comment

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.

LGTM, I just left one comment 🚀

@avivkeller avivkeller merged commit b96e4e5 into nodejs:main Jun 16, 2026
21 checks passed
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.

4 participants