Skip to content

perf(theme): MediaTheme and Lightbox pages no longer load the full token set for the backdrop measurement's cache key - #14300

Open
cixzhang wants to merge 4 commits into
mainfrom
perf/use-auto-media-mode-theme-key
Open

cixzhang wants to merge 4 commits into
mainfrom
perf/use-auto-media-mode-theme-key

Conversation

@cixzhang

@cixzhang cixzhang commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

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 calls useTheme. useAutoMediaMode called useTheme() only to use the resolved tokens object as a cache key for its probe, and useTheme resolves every token (resolveThemeTokens and the default token tables). On a page with MediaTheme alone 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 of useTheme that reads the theme and resolves the color mode (the Theme context, the nearest mode, <html data-theme>, and the system scheme) moves into useThemeIdentity, an internal hook that does not resolve tokens. useTheme calls it and then resolves its tokens as before.
  • hooks/useAutoMediaMode.ts: the probe cache keys on that theme and mode in place of the tokens object, which was a stable reference for exactly the same theme and mode.
  • No new Effect, state, or module.

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's main; first-load JavaScript, minified / gzip):

Page Base Head Change
docs, form, menu +0 / +0
table 374,803 / 127,194 374,803 / 127,191 +0 / −3
Toast 334,972 / 108,613 335,075 / 108,661 +103 / +48
Lightbox 464,110 / 154,011 434,377 / 144,363 −29,733 / −9,648
MediaTheme alone 40,115 / 13,257 9,090 / 3,728 −31,025 / −9,529
Toast + Button 334,985 / 108,625 335,088 / 108,663 +103 / +38
Button 201,494 / 67,474 201,494 / 67,474 +0 / +0
Button + MediaTheme 238,319 / 79,654 208,590 / 70,072 −29,729 / −9,582

Toast calls useTheme itself, 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 a Theme provider, which already loads part of the same token code, a MediaTheme page saves about 2.6 KB and a Lightbox page about 3.3 KB.

  • New 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.
  • Existing 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)

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • vitest run hooks/useAutoMediaMode, theme, Toast, Lightbox and OverlayScrim: green (2,389 tests).
  • pnpm size:pages as above.

@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Dec 4, 2026 6:42am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 4, 2026
@astracat-bot

astracat-bot Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Dec 4, 2026, 11:54 AM UTC

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 656c833

Storybook · Sandbox · built from this PR's head

Modified components

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

@cixzhang

cixzhang commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 1e0603c

@cixzhang
cixzhang marked this pull request as ready for review December 4, 2026 04:43

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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/core does not build — useThemeIdentity declares theme: DefinedTheme | undefined (packages/core/src/theme/useTheme.ts:538) but returns ctx?.theme ?? getRegisteredTheme(rootThemeName), and getRegisteredTheme returns DefinedTheme | null, so tsc --project tsconfig.build.json stops at :562 with TS2322 (in CI's typecheck job on this head, and reproduced locally, where the base passes) and declaring the field DefinedTheme | null makes 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 useTheme resolves 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.md clear; packages/core/src/hooks/useAutoMediaMode.reprobe.test.tsx clear; packages/core/src/hooks/useAutoMediaMode.ts clear; packages/core/src/theme/useTheme.ts carries the finding above.

Automated review (maintainer link)

Comment thread packages/core/src/theme/useTheme.ts Resolved

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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/core does not build — useThemeIdentity declares theme: DefinedTheme | undefined (packages/core/src/theme/useTheme.ts:538) but returns getRegisteredTheme's DefinedTheme | null, so tsc --project tsconfig.build.json fails at :562 with TS2322 in CI's typecheck job and when reproduced locally, and declaring the field DefinedTheme | null makes it pass.
  • Miss: The changeset's 9.5 KB saving does not hold under a Theme provider — measured locally with pnpm size:pages, a page that renders Theme and MediaTheme (the getting-started setup, with no useTheme call) drops 2,632 B gzip and Theme with Lightbox 3,273 B, because Theme already imports part of the same token code (statusRoleDefaults and tokenReferences, through generateThemeRules.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 no Theme provider, 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 useTheme call — verified on the base side of the same measurement.
  • About 9.5 KB gzip on a page with MediaTheme alone — 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 useTheme resolves 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 useTheme itself — 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.md carries the second finding; packages/core/src/hooks/useAutoMediaMode.reprobe.test.tsx clear; packages/core/src/hooks/useAutoMediaMode.ts clear; packages/core/src/theme/useTheme.ts carries the first finding.

Automated review (maintainer link)

…'s saving under a Theme provider

Co-authored-by: JasonOA888 <JasonOA888@users.noreply.github.com>

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 writes this in 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, MediaTheme and Lightbox pages no longer load the full token set for the measurement's cache key: verified (the measurement imports only useThemeIdentity, useAutoMediaMode.ts:28, :145; token resolution stays in useTheme, useTheme.ts:596-599; the bundle was measured locally on this head).
    • The measurement called useTheme only for its tokens cache key, and useTheme resolves every token: verified (the removed lines of useAutoMediaMode.ts; useTheme.ts:596-599).
    • About 9.5 KB gzip on a MediaTheme-only page, the size table, the Toast growth and the 2.6 / 3.3 KB savings under a Theme: 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-181 against useTheme.ts:596-599; mediaSide.ts untouched; the re-probe test passes in CI).
    • The theme-and-mode read moves into the internal useThemeIdentity, and useTheme resolves its tokens as before: verified (moved lines identical; useTheme.ts:537-563, :593-599).
    • The old tokens object was a stable reference for exactly the same theme and mode: verified (useMemo keyed on [theme, effectiveMode]).
    • No new Effect, state or module: verified (diff).
    • Toast calls useTheme itself, 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-theme change with no Theme above: verified (useAutoMediaMode.reprobe.test.tsx:55-99; passes in CI's test-ui).
    • Existing useTheme, theme, Toast, Lightbox and OverlayScrim tests pass unchanged: verified (the diff leaves them untouched; they pass in CI's test-ui shards); the 2,389-test count is reported.
    • The token-free read follows #13179, which first split it out of useTheme: verified (#13179 adds useThemeInputs to useTheme.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 Theme provider 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).
  • Files:
    • .changeset/use-auto-media-mode-theme-key.md: clear
    • packages/core/src/hooks/useAutoMediaMode.reprobe.test.tsx: clear
    • packages/core/src/hooks/useAutoMediaMode.ts: clear
    • packages/core/src/theme/useTheme.ts: clear

Automated review (maintainer link)

@cixzhang

cixzhang commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 656c833

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This pull request is reviewed as part of its stack; see the review on #12410.

Automated review (maintainer link)

This branch was successfully deployed

1 active deployment
Preview — 656c8338 Deployed Dec 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant