Repository navigation
Conversation
…he color mode, not the resolved tokens
Co-authored-by: JasonOA888 <JasonOA888@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| lab/CommentThread | 377.5 kB (+57 B) · 2.4 kB CSS (0) | — | — · — · — |
| lab/Comments | 384.5 kB (+42 B) · 2.5 kB CSS (0) | — | — · — · — |
| Toast | 111.2 kB (+41 B) · 11.7 kB CSS (0) | — | — · — · — |
✓ passed · ✗ needs a fix · Δ changed, for review in the shots below · ↻ needs re-verify · — did not run
132 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| Markdown | 202.5 kB (+15 B) · 23.9 kB CSS (0) | — | — · — · — |
| lab/ListInput | 102.9 kB (+15 B) · 1.3 kB CSS (0) | — | — · — · — |
| charts/Chart | 261.5 kB (+10 B) · 529 B CSS (0) | — | — · — · — |
| AppShell | 95.6 kB (+3 B) · 15.2 kB CSS (0) | — | — · — · — |
| TopNavHeading | 93.3 kB (+3 B) · 12.7 kB CSS (0) | — | — · — · — |
| SideNavHeading | 94.2 kB (+2 B) · 12.8 kB CSS (0) | — | — · — · — |
| BreadcrumbItem | 108.1 kB (+1 B) · 14.3 kB CSS (0) | — | — · — · — |
| Timestamp | 28.8 kB (+1 B) · 11.6 kB CSS (0) | — | — · — · — |
| AlertDialog | 138.5 kB (0) · 16.5 kB CSS (0) | — | — · — · — |
| Banner | 73.3 kB (0) · 11.9 kB CSS (0) | — | — · — · — |
| BaseTypeahead | 88.7 kB (0) · 12.4 kB CSS (0) | — | — · — · — |
| Button | 71.2 kB (0) · 11.3 kB CSS (0) | — | — · — · — |
| ButtonGroup | 45.3 kB (0) · 3.8 kB CSS (0) | — | — · — · — |
| Calendar | 82.4 kB (0) · 12.0 kB CSS (0) | — | — · — · — |
| Carousel | 83.1 kB (0) · 12.4 kB CSS (0) | — | — · — · — |
| ChatComposer | 95.7 kB (0) · 14.0 kB CSS (0) | — | — · — · — |
| ChatComposerInput | 92.8 kB (0) · 12.8 kB CSS (0) | — | — · — · — |
| ChatComposerTokenElement | 92.8 kB (0) · 12.8 kB CSS (0) | — | — · — · — |
| ChatDictationButton | 71.8 kB (0) · 11.4 kB CSS (0) | — | — · — · — |
| ChatLayout | 95.0 kB (0) · 11.9 kB CSS (0) | — | — · — · — |
| ChatLayoutScrollButton | 71.7 kB (0) · 11.5 kB CSS (0) | — | — · — · — |
| ChatMessageList | 29.5 kB (0) · 7.9 kB CSS (0) | — | — · — · — |
| ChatMessageMetadata | 21.0 kB (0) · 4.2 kB CSS (0) | — | — · — · — |
| ChatSendButton | 71.6 kB (0) · 11.3 kB CSS (0) | — | — · — · — |
| ChatToolCalls | 34.0 kB (0) · 9.3 kB CSS (0) | — | — · — · — |
| CheckboxInput | 74.2 kB (0) · 11.1 kB CSS (0) | — | — · — · — |
| CheckboxList | 69.3 kB (0) · 8.5 kB CSS (0) | — | — · — · — |
| CheckboxListItem | 85.9 kB (0) · 13.1 kB CSS (0) | — | — · — · — |
| CheckIndicator | 9.0 kB (0) · 681 B CSS (0) | — | — · — · — |
| Citation | 21.4 kB (0) · 4.6 kB CSS (0) | — | — · — · — |
| CodeBlock | 87.6 kB (0) · 13.1 kB CSS (0) | — | — · — · — |
| CommandPalette | 88.1 kB (0) · 14.0 kB CSS (0) | — | — · — · — |
| CommandPaletteInput | 35.1 kB (0) · 8.4 kB CSS (0) | — | — · — · — |
| ComplexSelector | 88.6 kB (0) · 13.7 kB CSS (0) | — | — · — · — |
| ContextMenu | 111.5 kB (0) · 20.0 kB CSS (0) | — | — · — · — |
| ContextMenuItem | 42.4 kB (0) · 7.4 kB CSS (0) | — | — · — · — |
| DateInput | 215.0 kB (0) · 19.5 kB CSS (0) | — | — · — · — |
| DateRangeInput | 101.9 kB (0) · 14.6 kB CSS (0) | — | — · — · — |
| DateTimeInput | 239.0 kB (0) · 21.3 kB CSS (0) | — | — · — · — |
| DialogHeader | 74.5 kB (0) · 13.0 kB CSS (0) | — | — · — · — |
| DrawerHeader | 74.6 kB (0) · 14.5 kB CSS (0) | — | — · — · — |
| DropdownMenu | 138.8 kB (0) · 20.2 kB CSS (0) | — | — · — · — |
| DropdownMenuCheckboxItem | 30.6 kB (0) · 7.8 kB CSS (0) | — | — · — · — |
| DropdownMenuItem | 29.7 kB (0) · 7.2 kB CSS (0) | — | — · — · — |
| DropdownMenuRadioItem | 30.6 kB (0) · 7.8 kB CSS (0) | — | — · — · — |
| DropdownMenuSubMenu | 84.1 kB (0) · 11.6 kB CSS (0) | — | — · — · — |
| Field | 64.0 kB (0) · 8.0 kB CSS (0) | — | — · — · — |
| FieldLabel | 59.5 kB (0) · 6.5 kB CSS (0) | — | — · — · — |
| FieldStatus | 10.9 kB (0) · 3.7 kB CSS (0) | — | — · — · — |
| FileInput | 81.7 kB (0) · 13.2 kB CSS (0) | — | — · — · — |
| Icon | 8.8 kB (0) · 681 B CSS (0) | — | — · — · — |
| IconButton | 71.2 kB (0) · 11.3 kB CSS (0) | — | — · — · — |
| InfoTip | 53.9 kB (0) · 6.1 kB CSS (0) | — | — · — · — |
| InputGroup | 66.2 kB (0) · 9.5 kB CSS (0) | — | — · — · — |
| Link | 61.3 kB (0) · 7.8 kB CSS (0) | — | — · — · — |
| ListItem | 85.1 kB (0) · 13.1 kB CSS (0) | — | — · — · — |
| MobileNav | 84.0 kB (0) · 12.0 kB CSS (0) | — | — · — · — |
| MobileNavToggle | 73.4 kB (0) · 12.0 kB CSS (0) | — | — · — · — |
| MoreMenu | 139.0 kB (0) · 20.2 kB CSS (0) | — | — · — · — |
| MultiSelector | 110.9 kB (0) · 19.5 kB CSS (0) | — | — · — · — |
| NavHeadingMenuItem | 20.3 kB (0) · 7.1 kB CSS (0) | — | — · — · — |
| NumberInput | 110.5 kB (0) · 13.5 kB CSS (0) | — | — · — · — |
| Pagination | 156.1 kB (0) · 20.6 kB CSS (0) | — | — · — · — |
| Popover | 110.5 kB (0) · 15.9 kB CSS (0) | — | — · — · — |
| PowerSearch | 328.0 kB (0) · 27.9 kB CSS (0) | — | — · — · — |
| ProgressBar | 12.5 kB (0) · 7.1 kB CSS (0) | — | — · — · — |
| RadioList | 65.5 kB (0) · 8.0 kB CSS (0) | — | — · — · — |
| RadioListItem | 82.0 kB (0) · 11.7 kB CSS (0) | — | — · — · — |
| SegmentedControl | 105.9 kB (0) · 7.8 kB CSS (0) | — | — · — · — |
| Selector | 122.8 kB (0) · 20.2 kB CSS (0) | — | — · — · — |
| SelectorOption | 25.9 kB (0) · 6.9 kB CSS (0) | — | — · — · — |
| SideNav | 120.1 kB (0) · 12.8 kB CSS (0) | — | — · — · — |
| SideNavCollapseButton | 72.2 kB (0) · 11.4 kB CSS (0) | — | — · — · — |
| SideNavItem | 87.5 kB (0) · 12.6 kB CSS (0) | — | — · — · — |
| Slider | 120.0 kB (0) · 9.7 kB CSS (0) | — | — · — · — |
| Step | 32.7 kB (0) · 5.8 kB CSS (0) | — | — · — · — |
| Stepper | 72.9 kB (0) · 11.5 kB CSS (0) | — | — · — · — |
| Switch | 114.7 kB (0) · 11.0 kB CSS (0) | — | — · — · — |
| Table | 127.3 kB (0) · 21.6 kB CSS (0) | — | — · — · — |
| TableCell | 112.6 kB (0) · 20.7 kB CSS (0) | — | — · — · — |
| TableHeaderCell | 112.5 kB (0) · 20.4 kB CSS (0) | — | — · — · — |
| TableSelectionToolbar | 81.8 kB (0) · 14.9 kB CSS (0) | — | — · — · — |
| TabList | 49.4 kB (0) · 7.0 kB CSS (0) | — | — · — · — |
| TabMenu | 89.5 kB (0) · 12.7 kB CSS (0) | — | — · — · — |
| TextArea | 98.0 kB (0) · 10.6 kB CSS (0) | — | — · — · — |
| TextInput | 105.2 kB (0) · 13.2 kB CSS (0) | — | — · — · — |
| Thumbnail | 75.9 kB (0) · 12.9 kB CSS (0) | — | — · — · — |
| TimeInput | 187.2 kB (0) · 18.3 kB CSS (0) | — | — · — · — |
| ToggleButton | 71.9 kB (0) · 11.4 kB CSS (0) | — | — · — · — |
| ToggleButtonGroup | 42.5 kB (0) · 3.8 kB CSS (0) | — | — · — · — |
| Token | 31.7 kB (0) · 5.1 kB CSS (0) | — | — · — · — |
| Tokenizer | 119.1 kB (0) · 22.5 kB CSS (0) | — | — · — · — |
| TopNav | 75.2 kB (0) · 12.4 kB CSS (0) | — | — · — · — |
| TopNavMegaMenu | 86.4 kB (0) · 13.4 kB CSS (0) | — | — · — · — |
| TopNavMenu | 92.5 kB (0) · 12.7 kB CSS (0) | — | — · — · — |
| TreeList | 48.3 kB (0) · 6.1 kB CSS (0) | — | — · — · — |
| Typeahead | 100.4 kB (0) · 14.9 kB CSS (0) | — | — · — · — |
| lab/AudioPlayer | 242.1 kB (0) · 1.8 kB CSS (0) | — | — · — · — |
| lab/ChatEmojiPicker | 134.2 kB (0) · 773 B CSS (0) | — | — · — · — |
| lab/ChatReactionBar | 135.7 kB (0) · 1.1 kB CSS (0) | — | — · — · — |
| lab/CommentComposer | 193.1 kB (0) · 1.9 kB CSS (0) | — | — · — · — |
| lab/CommentPin | 64.0 kB (0) · 1.2 kB CSS (0) | — | — · — · — |
| lab/DiffViewer | 100.5 kB (0) · 2.3 kB CSS (0) | — | — · — · — |
| lab/EmojiPicker | 125.2 kB (0) · 751 B CSS (0) | — | — · — · — |
| lab/MediaCaptionsButton | 231.6 kB (0) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaFullscreenButton | 231.6 kB (0) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaPlaybackRate | 231.6 kB (0) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaPlayButton | 231.6 kB (0) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaSeekButton | 231.6 kB (0) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaTime | 231.6 kB (0) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaTimeSlider | 231.6 kB (0) · 1.5 kB CSS (0) | — | — · — · — |
| lab/MediaVolume | 231.6 kB (0) · 1.5 kB CSS (0) | — | — · — · — |
| lab/NavigationScreen | 87.2 kB (0) · 1.5 kB CSS (0) | — | — · — · — |
| lab/NavigationStack | 87.2 kB (0) · 1.5 kB CSS (0) | — | — · — · — |
| lab/PageControl | 79.6 kB (0) · 716 B CSS (0) | — | — · — · — |
| lab/Schedule | 123.1 kB (0) · 3.9 kB CSS (0) | — | — · — · — |
| lab/SelectableCardGroup | 74.5 kB (0) · 162 B CSS (0) | — | — · — · — |
| lab/TabBar | 85.1 kB (0) · 1.8 kB CSS (0) | — | — · — · — |
| lab/TabBarItem | 3.9 kB (0) · 1.8 kB CSS (0) | — | — · — · — |
| lab/TabBarMoreList | 98.9 kB (0) · 1.8 kB CSS (0) | — | — · — · — |
| lab/Tour | 112.7 kB (0) · 1.0 kB CSS (0) | — | — · — · — |
| lab/TransferList | 134.8 kB (0) · 1.4 kB CSS (0) | — | — · — · — |
| lab/TransferListSelector | 147.6 kB (0) · 1.6 kB CSS (0) | — | — · — · — |
| richtext/RichTextEditor | 315.1 kB (0) · 2.7 kB CSS (0) | — | — · — · — |
| richtext/RichTextEditorToolbar | 299.6 kB (0) · 454 B CSS (0) | — | — · — · — |
| richtext/RichTextView | 291.7 kB (0) · 2.4 kB CSS (0) | — | — · — · — |
| Collapsible | 30.2 kB (−1 B) · 4.7 kB CSS (0) | — | — · — · — |
| Spinner | 26.0 kB (−3 B) · 7.0 kB CSS (0) | — | — · — · — |
| lab/VideoPlayer | 237.5 kB (−2.6 kB) · 2.1 kB CSS (0) | — | — · — · — |
| Overlay | 16.3 kB (−8.9 kB) · 4.3 kB CSS (0) | — | — · — · — |
| Lightbox | 146.5 kB (−9.4 kB) · 12.5 kB CSS (0) | — | — · — · — |
| lab/DialogHeroHeader | 86.6 kB (−9.5 kB) · 372 B CSS (0) | — | — · — · — |
Package size: @astryxdesign/core 8.18 MB packed (+355 B); no new dependencies.
Wide change (shared styles: packages/core/src/theme/useTheme.ts): add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.
Generated by PR Enrichment workflow | View full report
|
/approve-spec 1e0603c |
There was a problem hiding this comment.
Changes requested. One build-breaking type error; everything else in this change checks out, and the first-load saving is real (measured here: a MediaTheme page drops 13,315 → 3,722 B gzip, a Lightbox page 154,690 → 144,983 B, an Overlay page 21,907 → 12,772 B, while a Toast page grows 44 B).
- The head does not typecheck, so
@astryxdesign/coredoes not build —useThemeIdentitydeclarestheme: DefinedTheme | undefined(packages/core/src/theme/useTheme.ts:538) but returnsctx?.theme ?? getRegisteredTheme(rootThemeName), andgetRegisteredThemereturnsDefinedTheme | null, sotsc --project tsconfig.build.jsonstops at:562withTS2322(in CI'stypecheckjob on this head, and reproduced locally, where the base passes) and declaring the fieldDefinedTheme | nullmakes the Core build complete.
The cache key itself is sound: tokens was memoized on exactly [theme, effectiveMode], so the probe re-runs on the same changes, and the new useAutoMediaMode.reprobe.test.tsx pins that (run locally with the existing theme, Toast, Lightbox and Overlay suites: 2,428 tests green). CI's typecheck job on this head reports the same error; its red build, test and docsite-test jobs are the deferred heavy-CI step, not failures of this change.
Claims and files checked
Review mode: full; reason: no-earlier-review
- Title's claim that MediaTheme and Lightbox pages no longer load the full token set — verified by measuring both pages here.
- The probe re-measures on exactly the same changes as before (backdrop, theme, resolved mode) — verified: the old key was memoized on the theme and the resolved mode, and the new test exercises an unchanged render, a mode change, a theme change and a root attribute change.
- Picking a side is unchanged — verified: the side picker and the painted-colour resolution are untouched.
- The theme-and-mode read moves into a token-free internal hook and
useThemeresolves tokens from it — verified line for line. - No new Effect, state or module — verified.
- No public API, product behavior, visual direction or policy change — verified: nothing in the diff reaches a package export, token, attribute or default.
- Per-page first-load sizes in the description — your own measurements; re-measured here and they agree in sign and magnitude.
- Existing theme, Toast, Lightbox and Overlay tests pass unchanged — verified here.
- The credit note about the earlier pull request's narrower cut — verified against that pull request's diff.
- The changeset's wording and bump — verified; the changeset check passes.
- Files:
.changeset/use-auto-media-mode-theme-key.mdclear;packages/core/src/hooks/useAutoMediaMode.reprobe.test.tsxclear;packages/core/src/hooks/useAutoMediaMode.tsclear;packages/core/src/theme/useTheme.tscarries the finding above.
There was a problem hiding this comment.
Changes requested. Two fixes are needed before this can merge; the cache-key change itself is sound, and the new re-probe test plus the existing hooks, theme, Toast, Lightbox and Overlay suites pass locally (2,428 tests).
- The head does not typecheck, so
@astryxdesign/coredoes not build —useThemeIdentitydeclarestheme: DefinedTheme | undefined(packages/core/src/theme/useTheme.ts:538) but returnsgetRegisteredTheme'sDefinedTheme | null, sotsc --project tsconfig.build.jsonfails at:562with TS2322 in CI'stypecheckjob and when reproduced locally, and declaring the fieldDefinedTheme | nullmakes it pass. - Miss: The changeset's 9.5 KB saving does not hold under a
Themeprovider — measured locally withpnpm size:pages, a page that rendersThemeandMediaTheme(the getting-started setup, with nouseThemecall) drops 2,632 B gzip andThemewithLightbox3,273 B, becauseThemealready imports part of the same token code (statusRoleDefaultsandtokenReferences, throughgenerateThemeRules.ts), so please bound the number in.changeset/use-auto-media-mode-theme-key.md(for example "about 9.5 KB gzip on a page with noThemeprovider, and about 2.6 to 3.3 KB under one").
Claims and files checked
Review mode: same-head; reason: none
- Title "perf(theme): MediaTheme and Lightbox pages no longer load the full token set for the backdrop measurement's cache key" — verified: measured locally, the measurement no longer pulls token resolution into either page.
- Backdrop-measuring pages pay for the full default token set on the base even with no
useThemecall — verified on the base side of the same measurement. - About 9.5 KB gzip on a page with
MediaThemealone — your measurement; 9,593 B locally, which agrees. - The probe re-runs exactly when it did before (backdrop, theme, resolved mode) — verified: the old key was memoized on the theme and the resolved mode, and the new test exercises an unchanged render, a mode change, a theme change and a root attribute change.
- Picking a side is unchanged — verified: the side picker and the painted-colour resolution are untouched.
- The theme-and-mode read moves into a token-free internal hook that
useThemeresolves its tokens from — verified line for line; its added return type is the first finding. - The cache key uses that theme and mode in place of the token map — verified.
- No new Effect, state or module — verified.
- The per-page size table and its command against this branch's merge base — your measurement; the command is a valid size-script invocation, and locally the minified sizes match exactly and the gzip changes agree within about 1%.
- Toast keeps the token set because it calls
useThemeitself — verified; a Toast page grows 44 B gzip locally. - The new re-probe test covers each listed case — verified: both tests run those cases and pass locally.
- Existing useTheme, theme, Toast, Lightbox and OverlayScrim tests pass unchanged — verified locally; no existing test file changes.
- The test and size runs under Testing — your runs.
- The credit to the earlier pull request's narrower cut — verified against that pull request's diff.
- No public API, product behavior, visual direction or policy change, and no internal context in public text — verified.
- Changeset: patch bump, no full token resolution, same re-measure triggers — verified; about 9.5 KB less for every such page — false (second finding).
- Files:
.changeset/use-auto-media-mode-theme-key.mdcarries the second finding;packages/core/src/hooks/useAutoMediaMode.reprobe.test.tsxclear;packages/core/src/hooks/useAutoMediaMode.tsclear;packages/core/src/theme/useTheme.tscarries the first finding.
…'s saving under a Theme provider Co-authored-by: JasonOA888 <JasonOA888@users.noreply.github.com>
There was a problem hiding this comment.
Approved. The new cache key compares the same theme and resolved mode that keyed the old tokens memo, so the backdrop measurement runs again on exactly the same changes while pages that never call useTheme stop loading the token tables. CI is green on this head, including the build, typecheck and test jobs with the new re-probe test.
- The
Stack:line is not identical across the stack yet: #14311 writesthisin place of#14311, and #12410 adds a trailing clause after#12410, so these pull requests are still reviewed one by one; copy the exact line into both bodies if they should be reviewed as one stack.
Claims and files checked
Review mode: same-head; reason: none
- Changed rules (0): none
- Live title: perf(theme): MediaTheme and Lightbox pages no longer load the full token set for the backdrop measurement's cache key
- Claims:
- Title,
MediaThemeandLightboxpages no longer load the full token set for the measurement's cache key: verified (the measurement imports onlyuseThemeIdentity,useAutoMediaMode.ts:28,:145; token resolution stays inuseTheme,useTheme.ts:596-599; the bundle was measured locally on this head). - The measurement called
useThemeonly for itstokenscache key, anduseThemeresolves every token: verified (the removed lines ofuseAutoMediaMode.ts;useTheme.ts:596-599). - About 9.5 KB gzip on a
MediaTheme-only page, the size table, theToastgrowth and the 2.6 / 3.3 KB savings under aTheme: reported; re-measured locally on this head, within a few bytes gzip. - The probe runs again exactly when it did before, and picking a side is unchanged: verified (the key compares the memo's own inputs,
useAutoMediaMode.ts:173-181againstuseTheme.ts:596-599;mediaSide.tsuntouched; the re-probe test passes in CI). - The theme-and-mode read moves into the internal
useThemeIdentity, anduseThemeresolves its tokens as before: verified (moved lines identical;useTheme.ts:537-563,:593-599). - The old
tokensobject was a stable reference for exactly the same theme and mode: verified (useMemokeyed on[theme, effectiveMode]). - No new Effect, state or module: verified (diff).
ToastcallsuseThemeitself, so it keeps the token set: verified (Toast.tsx:448).- The new test covers an unchanged render, a mode change, a theme change, and a root
data-themechange with noThemeabove: verified (useAutoMediaMode.reprobe.test.tsx:55-99; passes in CI'stest-ui). - Existing
useTheme, theme,Toast,LightboxandOverlayScrimtests pass unchanged: verified (the diff leaves them untouched; they pass in CI'stest-uishards); the 2,389-test count is reported. - The token-free read follows #13179, which first split it out of
useTheme: verified (#13179 addsuseThemeInputstouseTheme.ts). - Scope is theme (
useTheme) and hooks (useAutoMediaMode): verified (the two changed source files). - No public API, product behaviour, visual or policy change: verified (CI's API report lists 0 rows; behaviour equivalence above).
- Public text carries no internal context: verified.
- The four pull requests form one stack: not yet (each head contains the one before, but the line differs in #14311 and #12410; see the note above).
- Changeset, less JavaScript by about 9.5 KB without a
Themeprovider and 2.6 to 3.3 KB under one: reported; re-measured locally on this head. - Changeset, the measurement decides from the theme and the color mode and measures again on the same changes: verified (as above).
- Title,
- Files:
.changeset/use-auto-media-mode-theme-key.md: clearpackages/core/src/hooks/useAutoMediaMode.reprobe.test.tsx: clearpackages/core/src/hooks/useAutoMediaMode.ts: clearpackages/core/src/theme/useTheme.ts: clear
|
/approve-spec 656c833 |
There was a problem hiding this comment.
This pull request is reviewed as part of its stack; see the review on #12410.
Stack: #14300 → #14302 → #14311 → #12410
Maintainer impact
A page that renders
MediaTheme,Lightbox, or another surface that measures its backdrop pays for the theme's full default token set even when nothing on it callsuseTheme.useAutoMediaModecalleduseTheme()only to use the resolvedtokensobject as a cache key for its probe, anduseThemeresolves every token (resolveThemeTokensand the default token tables). On a page withMediaThemealone that is about 9.5 KB gzip of first-load JavaScript.Intended invariant
The probe runs again exactly when it did before: when the painted backdrop changes, or when the theme or the resolved color mode changes (the cache rule in
hooks/useAutoMediaMode.ts). Picking a side is unchanged.Change
theme/useTheme.ts: the part ofuseThemethat reads the theme and resolves the color mode (the Theme context, the nearest mode,<html data-theme>, and the system scheme) moves intouseThemeIdentity, an internal hook that does not resolve tokens.useThemecalls it and then resolves its tokens as before.hooks/useAutoMediaMode.ts: the probe cache keys on that theme and mode in place of thetokensobject, which was a stable reference for exactly the same theme and mode.Evidence
pnpm size:pages --base 8c5743ea3c8729620fd28585e8e6e1e3ee74d973 --page toast=Toast --page lightbox=Lightbox --page mediatheme=theme:MediaTheme --page toastbutton=Toast,Button --page button=Button --page buttonmedia=Button,theme:MediaTheme(base: this branch'smain; first-load JavaScript, minified / gzip):ToastLightboxMediaThemealoneToast+ButtonButtonButton+MediaThemeToast calls
useThemeitself, so it keeps the token set and gains the small hook: +48 B gzip on a Toast page and +38 B on a Toast and Button page. Under aThemeprovider, which already loads part of the same token code, aMediaThemepage saves about 2.6 KB and aLightboxpage about 3.3 KB.hooks/useAutoMediaMode.reprobe.test.tsx: under a Theme, a render that changes neither the theme nor the mode adds no probe, and a mode change and a theme change each probe again; with no Theme above, a<html data-theme>change probes again.useTheme, theme, Toast, Lightbox and OverlayScrim tests pass unchanged.Credit
The token-free theme read follows JasonOA888's #13179, which first split it out of
useTheme; this pull request keeps only that cut. #13179's shared painted-color cache and its fixed-mode subscription gate are a separate follow-up.Overlap checked: #13179 (this narrower cut supersedes it, with credit; its other parts follow separately)
Scope
Components: theme (useTheme), hooks (useAutoMediaMode)
Testing
vitest runhooks/useAutoMediaMode, theme, Toast, Lightbox and OverlayScrim: green (2,389 tests).pnpm size:pagesas above.