fix: sync dark mode to the page background in full-page shells - #1549
Conversation
With dark mode enabled, the page around Studio (overscroll areas and the space behind Studio's rounded corners) stayed white because all Studio theming is scoped to the .ps root and never reached the document. The theme hook now syncs the resolved theme to the document root: it sets color-scheme and Studio's resolved --background color on <html> (marked with data-prisma-studio-theme) so the page canvas matches the active theme. Studio only claims the document when neither <html> nor <body> carries a host-authored background, so embedded hosts that style their own page are left untouched, and the document-level theme is removed again when Studio unmounts. The ppg demo shell drops its hardcoded light body background and uses light-dark() for its chrome so the demo follows the synced color-scheme. Fixes #1475 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 42 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughStudio now synchronizes its resolved theme to the document root when no host-authored page background exists, updating 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
|
Compute preview deployed. Branch: |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Warning
CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.
Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ui/hooks/use-theme.ts`:
- Around line 198-211: Update clearDocumentTheme and the related useTheme
ownership flow to track active instances, snapshot the original inline
color-scheme and background-color values when the first owner claims the
document, and release ownership per instance. Only remove the Studio theme and
restore both saved styles after the final owner releases it; unmounting one of
multiple active useTheme instances must leave the document unchanged.
- Around line 142-157: Update canOwnDocumentBackground so the Studio marker does
not permanently force ownership: re-check authored backgrounds on both
document.documentElement and document.body on every evaluation, relinquish
ownership when either is host-styled, and clear Studio-applied properties
through the existing theme-sync cleanup path. Add a test covering a host adding
a background after mount and verify Studio stops overriding it.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 115a6258-0357-4404-a164-09b6820c6e6e
📒 Files selected for processing (7)
.changeset/dark-mode-page-background.mdArchitecture/ui-state.mdFEATURES.mddemo/ppg-dev/DemoShell.tsxdemo/ppg-dev/server.tsui/hooks/use-theme.test.tsxui/hooks/use-theme.ts
Address review feedback on the document-level theme sync: - Host ownership is now re-evaluated on every sync instead of being sticky once the data-prisma-studio-theme marker exists. Studio's own inline values are ignored when judging "host-authored": they are temporarily swapped for the pre-claim originals before checking, and if the host authored a document background (or overwrote Studio's inline properties) after mount, Studio releases the claim and keeps the host's values. - Document theme claims are now owned by a module-level registry of mounted useTheme instances. The pre-claim inline <html> values (including any pre-existing host color-scheme) are snapshotted when the first owner claims the document and restored only when the last owner unmounts, so unmounting one of several Studio instances no longer clears the theme for the rest, and a host's inline color-scheme survives release. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fixes #1475
Root cause
All Studio theming is scoped to the
.psroot (:root→.psrewrite in postcss config), and the theme hook only toggleddarkon.psroots. Nothing ever reached<html>/<body>, so in full-page shells the page canvas stayed browser-default white — visible in overscroll areas and behind Studio's rounded corners.Fix
Rather than moving
ps darkto<html>(which would leak Studio styles into embedding hosts), the theme hook now syncs the resolved theme to the document root with an ownership guard:syncDocumentTheme()setscolor-schemeand Studio's resolved--background(read from the.psroot's computed style, so custom host themes are honored) on<html>, marked withdata-prisma-studio-theme.<html>nor<body>has a host-authored background — widget embeds (e.g. Console) are untouched. Everything is removed on unmount.light-dark()colors.Verification
<html>'scolor-scheme/background and the host-authored-background guard. Typecheck/lint clean; changeset included; behavior documented inArchitecture/ui-state.md.🤖 Generated with Claude Code