Skip to content

fix(Icon): preserve the nearest theme for icon resolution - #11498

Merged
cixzhang merged 3 commits into
meta:mainfrom
korkt-kim:korkt-kim/ast087-nearest-theme-icons
Nov 13, 2026
Merged

cixzhang merged 3 commits into
meta:mainfrom
korkt-kim:korkt-kim/ast087-nearest-theme-icons

Conversation

@korkt-kim

Copy link
Copy Markdown
Contributor

User impact

Two Theme objects can share a name but provide different icon artwork. Nesting them can make icons after the inner region use the inner artwork even though they remain under the outer provider. Registering an unused same-name theme can also replace a mounted provider's icons when only a descendant updates. Its token values still come from the original provider, leaving icons inconsistent with the surrounding theme.

Problem and solution fit

Icon readers reduce the nearest provider to its name, then look it up again in the last-write-wins registry. That loses the provider's object identity.

Icon, useIcon, and component icon-slot resolution now pass the nearest theme object through the existing private useThemeDefinition hook. The SVG-ref callback tracks that same resolver input. Without a provider, the existing registered root-theme fallback remains in place.

Expected behavior and authority

  • Theme application INV1: the nearest provider wins.
  • The same record's INV11 requires server rendering and hydration to resolve icon and slot requests consistently for the active theme.
  • Icon resolution INV6 and INV9 keep slot/artwork precedence and active-theme selection with their existing owners.

Smallest restoration

Two implementation files, two regression cases in one test file, and a Core patch changeset. The tests cover same-name nesting through server rendering and hydration, and an unused registration followed by a descendant-only update.

Evidence

  • Before: the nested fixture renders outer → inner → inner artwork. Registering another same-name theme changes all three icon readers to its artwork while the provider token stays unchanged.
  • After: the nested fixture renders outer → inner → outer. The descendant keeps its provider's artwork after an unrelated registration.
  • Representative unchanged path: the outer row before nesting and the inner row retain their own artwork in both versions. Restoring the outer registration recovers the original readers; the corrected readers remain on their provider throughout.
  • Regression proof: both focused cases reproduce the incorrect result with the base Icon/useIcon modules and pass with this change.

Both videos use the same local Storybook fixture and interaction sequence in Playwright Chromium 149 at 1200 × 820. AS-IS loads the three icon-reader modules from base a4fe0154fb; TO-BE loads the proposed implementation. Both share the remaining source modules. Recording fixtures and media are not part of the branch diff.

AS-IS

nearest-theme-icons-as-is.mp4

TO-BE

nearest-theme-icons-to-be-final.mp4

Scope

Components: Icon, useIcon, component icon-slot resolution

  • One defect is restored: icon readers lose the nearest provider's identity.
  • Separable tagalongs are excluded; registration precedence and same-name CSS scoping stay unchanged.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm exec vitest run --project ui --maxWorkers=1 packages/core/src/Icon/nearestTheme.test.tsx — 2 passed.
  • Real-browser assertions for all three readers: same-name nesting, unused registration, unchanged provider token, and restored registration.
  • pnpm lint:strict — 0 errors; 238 warnings.
  • pnpm build.
  • pnpm -F @astryxdesign/core typecheck — source, all three test shards, and consumer docs.
  • Pre-commit checks, Prettier on the changed files, and git diff --check.

@vercel

vercel Bot commented Nov 13, 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 Nov 13, 2026 6:35pm UTC

Request Review

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

astracat-bot Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 13, 2026, 7:04 PM UTC

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 5cbd35d

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
RadioListItem 72.0 kB (+76 B) · 10.4 kB CSS (0) — — · — · —
CheckboxListItem 75.7 kB (+55 B) · 11.7 kB CSS (0) — — · — · —
lab/TransferListSelector 116.5 kB (+54 B) · 1.4 kB CSS (0) — — · — · —
112 more components
Component Size LoC Visual · A11y · RTL
lab/TransferList 107.6 kB (+53 B) · 1.2 kB CSS (0) — — · — · —
ContextMenuItem 33.5 kB (+52 B) · 6.8 kB CSS (0) — — · — · —
richtext/RichTextView 281.9 kB (+46 B) · 2.3 kB CSS (0) — — · — · —
ListItem 74.8 kB (+44 B) · 11.7 kB CSS (0) — — · — · —
lab/TabBarMoreList 97.5 kB (+43 B) · 1.8 kB CSS (0) — — · — · —
DropdownMenuCheckboxItem 23.9 kB (+42 B) · 7.0 kB CSS (0) — — · — · —
DropdownMenuRadioItem 24.0 kB (+37 B) · 7.0 kB CSS (0) — — · — · —
CheckboxInput 68.8 kB (+36 B) · 10.1 kB CSS (0) — — · — · —
Token 29.3 kB (+29 B) · 4.8 kB CSS (0) — — · — · —
Pagination 120.9 kB (+28 B) · 18.8 kB CSS (0) — — · — · —
lab/DialogHeroHeader 88.4 kB (+28 B) · 372 B CSS (0) — — · — · —
lab/ListInput 93.3 kB (+28 B) · 922 B CSS (0) — — · — · —
InfoTip 50.2 kB (+26 B) · 5.4 kB CSS (0) — — · — · —
CommandPalette 76.3 kB (+25 B) · 12.7 kB CSS (0) — — · — · —
Selector 109.8 kB (+25 B) · 18.4 kB CSS (0) — — · — · —
Timestamp 35.8 kB (+25 B) · 11.0 kB CSS (0) — — · — · —
Toast 103.3 kB (+25 B) · 11.1 kB CSS (0) — — · — · —
Carousel 74.5 kB (+23 B) · 11.7 kB CSS (0) — — · — · —
CommandPaletteInput 34.3 kB (+23 B) · 7.6 kB CSS (0) — — · — · —
TabMenu 78.7 kB (+23 B) · 11.9 kB CSS (0) — — · — · —
ChatMessageMetadata 20.4 kB (+21 B) · 4.1 kB CSS (0) — — · — · —
DropdownMenuSubMenu 74.4 kB (+21 B) · 10.1 kB CSS (0) — — · — · —
ComplexSelector 77.4 kB (+20 B) · 12.6 kB CSS (0) — — · — · —
Icon · Storybook 8.2 kB (+19 B) · 681 B CSS (0) 943 (0) ✓ · ✓ · —
TextArea 66.7 kB (+19 B) · 9.4 kB CSS (0) — — · — · —
MultiSelector 101.2 kB (+18 B) · 17.7 kB CSS (0) — — · — · —
TopNavHeading 81.9 kB (+18 B) · 12.0 kB CSS (0) — — · — · —
TopNavMenu 81.4 kB (+18 B) · 12.0 kB CSS (0) — — · — · —
ChatComposerInput 82.0 kB (+17 B) · 12.1 kB CSS (0) — — · — · —
ChatComposerTokenElement 82.0 kB (+17 B) · 12.1 kB CSS (0) — — · — · —
DateRangeInput 99.1 kB (+17 B) · 13.3 kB CSS (0) — — · — · —
DialogHeader 67.7 kB (+16 B) · 12.3 kB CSS (0) — — · — · —
FileInput 74.0 kB (+16 B) · 11.7 kB CSS (0) — — · — · —
SideNavHeading 82.3 kB (+16 B) · 12.1 kB CSS (0) — — · — · —
Typeahead 87.5 kB (+16 B) · 13.3 kB CSS (0) — — · — · —
Banner 66.9 kB (+15 B) · 11.3 kB CSS (0) — — · — · —
ChatToolCalls 34.9 kB (+15 B) · 8.4 kB CSS (0) — — · — · —
CheckIndicator 8.4 kB (+15 B) · 681 B CSS (0) — — · — · —
Citation 20.7 kB (+15 B) · 4.4 kB CSS (0) — — · — · —
FieldStatus 10.1 kB (+15 B) · 3.6 kB CSS (0) — — · — · —
MobileNavToggle 65.2 kB (+15 B) · 10.8 kB CSS (0) — — · — · —
Thumbnail 69.2 kB (+15 B) · 12.3 kB CSS (0) — — · — · —
FieldLabel 55.2 kB (+14 B) · 5.8 kB CSS (0) — — · — · —
RadioList 60.7 kB (+14 B) · 7.3 kB CSS (0) — — · — · —
SideNavItem 76.8 kB (+14 B) · 11.9 kB CSS (0) — — · — · —
TopNavMegaMenu 75.9 kB (+14 B) · 12.6 kB CSS (0) — — · — · —
ChatDictationButton 65.4 kB (+13 B) · 10.8 kB CSS (0) — — · — · —
richtext/RichTextEditorToolbar 298.3 kB (+13 B) · 454 B CSS (0) — — · — · —
ChatLayoutScrollButton 65.4 kB (+12 B) · 11.0 kB CSS (0) — — · — · —
SelectorOption 21.6 kB (+12 B) · 6.4 kB CSS (0) — — · — · —
Step 31.5 kB (+12 B) · 5.6 kB CSS (0) — — · — · —
Calendar 75.9 kB (+11 B) · 11.4 kB CSS (0) — — · — · —
DrawerHeader 67.9 kB (+11 B) · 13.7 kB CSS (0) — — · — · —
InputGroup 60.9 kB (+11 B) · 7.9 kB CSS (0) — — · — · —
Table 135.6 kB (+11 B) · 19.2 kB CSS (0) — — · — · —
TableSelectionToolbar 75.1 kB (+11 B) · 14.0 kB CSS (0) — — · — · —
TabList 47.1 kB (+11 B) · 6.5 kB CSS (0) — — · — · —
Button 64.9 kB (+10 B) · 10.8 kB CSS (0) — — · — · —
ChatSendButton 65.2 kB (+10 B) · 10.8 kB CSS (0) — — · — · —
DropdownMenuItem 23.1 kB (+10 B) · 6.6 kB CSS (0) — — · — · —
Collapsible 29.0 kB (+9 B) · 4.5 kB CSS (0) — — · — · —
Field 59.3 kB (+9 B) · 7.3 kB CSS (0) — — · — · —
IconButton 64.9 kB (+9 B) · 10.8 kB CSS (0) — — · — · —
TableHeaderCell 118.3 kB (+9 B) · 18.6 kB CSS (0) — — · — · —
ContextMenu 117.5 kB (+8 B) · 18.3 kB CSS (0) — — · — · —
MobileNav 75.8 kB (+8 B) · 11.4 kB CSS (0) — — · — · —
ChatComposer 84.3 kB (+7 B) · 12.9 kB CSS (0) — — · — · —
CheckboxList 73.0 kB (+7 B) · 7.8 kB CSS (0) — — · — · —
CodeBlock 79.9 kB (+7 B) · 12.1 kB CSS (0) — — · — · —
SideNavCollapseButton 65.7 kB (+7 B) · 10.8 kB CSS (0) — — · — · —
lab/DiffViewer 92.8 kB (+7 B) · 2.1 kB CSS (0) — — · — · —
lab/EmojiPicker 92.2 kB (+7 B) · 751 B CSS (0) — — · — · —
richtext/RichTextEditor 305.2 kB (+7 B) · 2.6 kB CSS (0) — — · — · —
BreadcrumbItem 91.6 kB (+6 B) · 12.9 kB CSS (0) — — · — · —
lab/Schedule 114.3 kB (+6 B) · 3.9 kB CSS (0) — — · — · —
DropdownMenu 104.2 kB (+5 B) · 18.5 kB CSS (0) — — · — · —
Stepper 66.6 kB (+5 B) · 10.9 kB CSS (0) — — · — · —
TableCell 118.7 kB (+5 B) · 18.8 kB CSS (0) — — · — · —
lab/Comments 367.3 kB (+5 B) · 2.5 kB CSS (0) — — · — · —
BaseTypeahead 78.1 kB (+4 B) · 11.7 kB CSS (0) — — · — · —
MoreMenu 104.4 kB (+4 B) · 18.5 kB CSS (0) — — · — · —
SideNav 120.6 kB (+4 B) · 12.2 kB CSS (0) — — · — · —
TextInput 72.6 kB (+4 B) · 12.0 kB CSS (0) — — · — · —
TopNav 77.5 kB (+2 B) · 11.7 kB CSS (0) — — · — · —
NumberInput 77.4 kB (0) · 12.2 kB CSS (0) — — · — · —
lab/TabBarItem 3.9 kB (0) · 1.8 kB CSS (0) — — · — · —
Link 56.2 kB (−1 B) · 7.1 kB CSS (0) — — · — · —
PowerSearch 306.1 kB (−1 B) · 25.3 kB CSS (0) — — · — · —
lab/CommentComposer 158.8 kB (−1 B) · 1.9 kB CSS (0) — — · — · —
lab/CommentPin 60.2 kB (−1 B) · 1.2 kB CSS (0) — — · — · —
Lightbox 145.1 kB (−2 B) · 11.9 kB CSS (0) — — · — · —
lab/TourStep 93.0 kB (−2 B) · 691 B CSS (0) — — · — · —
lab/CommentThread 360.5 kB (−3 B) · 2.4 kB CSS (0) — — · — · —
lab/SelectableCardGroup 68.6 kB (−9 B) · 162 B CSS (0) — — · — · —
Markdown 198.5 kB (−11 B) · 21.5 kB CSS (0) — — · — · —
lab/ChatReactionBar 113.9 kB (−16 B) · 1.1 kB CSS (0) — — · — · —
ToggleButton 91.8 kB (−17 B) · 10.9 kB CSS (0) — — · — · —
Tokenizer 103.4 kB (−19 B) · 20.0 kB CSS (0) — — · — · —
lab/TabBar 83.4 kB (−21 B) · 1.8 kB CSS (0) — — · — · —
AlertDialog 111.3 kB (−23 B) · 15.4 kB CSS (0) — — · — · —
lab/NavigationScreen 84.8 kB (−25 B) · 1.5 kB CSS (0) — — · — · —
lab/NavigationStack 84.8 kB (−25 B) · 1.5 kB CSS (0) — — · — · —
Slider 114.2 kB (−28 B) · 8.9 kB CSS (0) — — · — · —
Switch 108.7 kB (−28 B) · 10.0 kB CSS (0) — — · — · —
lab/ChatEmojiPicker 112.7 kB (−29 B) · 773 B CSS (0) — — · — · —
DateTimeInput 223.1 kB (−31 B) · 19.7 kB CSS (0) — — · — · —
ChatLayout 88.1 kB (−33 B) · 11.3 kB CSS (0) — — · — · —
DateInput 199.6 kB (−35 B) · 17.9 kB CSS (0) — — · — · —
TimeInput 174.4 kB (−40 B) · 16.9 kB CSS (0) — — · — · —
TreeList 46.1 kB (−40 B) · 5.9 kB CSS (0) — — · — · —
Popover 97.8 kB (−43 B) · 15.1 kB CSS (0) — — · — · —
AppShell 97.0 kB (−66 B) · 14.3 kB CSS (0) — — · — · —

Package size: @astryxdesign/core 7.52 MB packed (+10 B); no new dependencies.

Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

@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 pending CI: CI has not run on this head yet, so a maintainer adds the ci:run label to run it.

Icon, useIcon and component icon slots now follow the nearest Theme even when another theme shares its name, which is what the theme-application record's INV1 asks for. Both new tests fail without the change and pass with it, and the full Core test suite, Core typecheck and lint on the changed files pass locally. One optional follow-up: useThemeName's docs still suggest it for picking a semantic icon (useThemeName.doc.mjs and its JSDoc in useTheme.ts), so pointing icon readers to useIcon or <Icon> would keep custom code away from the same-name problem.

Claims and files checked
  • Changeset, icons, useIcon and slots use the nearest Theme's object: verified (Icon.tsx:413-414, useIcon.ts:38-40, useIcon.ts:52-54).
  • Changeset, nesting or registering a same-name theme no longer replaces their artwork: verified (nearestTheme.test.tsx; both cases fail on the base and pass here).
  • Changeset, icons outside a provider keep the registered root-theme fallback: verified (useTheme.ts:256, the same lookup as before).
  • Description, nested fixture goes from outer, inner, inner to outer, inner, outer: verified (test case 1 and a Storybook capture).
  • Description, an unused same-name registration flips icons on a descendant-only update while the token stays: verified (on the base, test case 2 fails at the readers after its token check passes).
  • Description, readers reduced the provider to its name and read a last-write-wins registry: verified (base readers used useThemeName; themeRegistry.ts:32-34).
  • Description, the existing internal useThemeDefinition is reused and the SVG ref tracks the same input: verified (useTheme.ts:248, unchanged; Icon.tsx:423).
  • Description, no new public API, default or interaction model, and registration precedence and CSS scoping unchanged: verified (built API surface unchanged; registry and Theme untouched).
  • Description, two implementation files, one test file with two cases, and a Core patch changeset: verified.
  • Description, focused tests, build and Core typecheck pass: verified; lint verified on the changed files only.
  • Description, AS-IS and TO-BE videos: not viewed; the tests and capture reproduce the same results.
  • .changeset/nearest-theme-icons.md: clear.
  • packages/core/src/Icon/Icon.tsx: clear.
  • packages/core/src/Icon/useIcon.ts: clear.
  • packages/core/src/Icon/nearestTheme.test.tsx: clear.

Automated review (maintainer link)

@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec f1e06e1

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 13, 2026
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec e384a14

@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 pending CI: CI is still running on this head.

Icon, useIcon and component icon slots now follow the nearest Theme even when another theme shares its name, which is what the theme-application record asks for. Both new tests fail without the change and pass with it, and a browser capture of Icon, useIcon and CodeBlock's copy icon shows the same before and after. One optional follow-up: useThemeName's docs still suggest it for picking a semantic icon (useThemeName.doc.mjs and its JSDoc in useTheme.ts), so pointing icon readers to useIcon or <Icon> would keep custom code away from the same-name problem.

Claims and files checked
  • Changeset, icons, useIcon and slots use the nearest Theme's object: verified (Icon.tsx:413-414, useIcon.ts:39-40, useIcon.ts:53-54).
  • Changeset, nesting or registering a same-name theme no longer replaces their artwork: verified (nearestTheme.test.tsx; both cases fail without the change and pass with it).
  • Changeset, icons outside a provider keep the registered root-theme fallback: verified (useTheme.ts:256, the same lookup as before).
  • Description, icons after a same-name inner region took the inner artwork: verified (test case 1 and a browser capture).
  • Description, an unused same-name registration flipped icons on a descendant-only update while the provider's token stayed: verified (without the change, test case 2 fails at the icon readers after its token check passes).
  • Description, readers reduced the provider to its name and read a last-write-wins registry: verified (the earlier readers used useThemeName; themeRegistry.ts:32-34).
  • Description, the existing private useThemeDefinition is reused and the SVG ref tracks the same input: verified (useTheme.ts:248, unchanged; Icon.tsx:423).
  • Description, the nearest provider wins, server and hydrated icons agree, and slot precedence and active-theme selection keep their owners: verified against the theme-application and icon-resolution records.
  • Description, the outer row before nesting and the inner row keep their own artwork in both versions: verified for the pull request's fixture; without the change, a component that renders again (CodeBlock's copy icon) can already take the inner artwork in that row.
  • Description, two implementation files, two regression cases in one test file and a Core patch changeset, with no recording fixtures in the diff: verified.
  • Description, no new public API, default or interaction model, and registration precedence and CSS scoping unchanged: verified (built API surfaces unchanged; registry and Theme untouched).
  • Description, focused tests, build, Core typecheck, lint and Prettier pass: verified; lint and Prettier checked on the changed files.
  • Description, before and after recordings: not viewed; the tests and a browser capture reproduce the same results.
  • .changeset/nearest-theme-icons.md: clear.
  • packages/core/src/Icon/Icon.tsx: clear.
  • packages/core/src/Icon/useIcon.ts: clear.
  • packages/core/src/Icon/nearestTheme.test.tsx: clear.

Automated review (maintainer link)

@cixzhang
cixzhang marked this pull request as draft November 13, 2026 17:26
@cixzhang
cixzhang marked this pull request as ready for review November 13, 2026 17:26
@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Nov 13, 2026
@cixzhang

Copy link
Copy Markdown
Contributor

/approve-spec 5cbd35d

@cixzhang
cixzhang marked this pull request as draft November 13, 2026 18:40
@cixzhang
cixzhang marked this pull request as ready for review November 13, 2026 18:41

@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 pending CI: CI is still running on this head.

Icon, useIcon and component icon slots now follow the nearest Theme object, which matches the nearest-provider rule; the new regression test fails without the change and passes with it, and nothing further is required for this pull request.

  • Miss: (non-blocking) Lab's CommentIcon (packages/lab/src/Comments/icons.tsx) still checks for an icon override by theme name, so after a nested same-name theme that overrides a comment:* key it can render no glyph; checking with useIcon(key) != null would keep it on the same theme as Icon, here or in a follow-up.
Claims and files checked
  • Changeset: icons, useIcon and component icon slots use the nearest Theme's object (verified in Icon.tsx and useIcon.ts).
  • Changeset: nesting or registering another same-name theme no longer replaces their artwork (verified by both regression cases and a browser capture).
  • Changeset: icons outside a provider keep the registered root-theme fallback (verified, the fallback code is unchanged).
  • Description: the nested and unused-registration failures, with tokens unchanged, reproduce on the base (verified).
  • Description: the root cause is a name lookup in a last-write-wins registry (verified).
  • Description: the fix uses the existing private theme-object hook and the SVG ref tracks the same input (verified).
  • Description: two implementation files, two test cases and a patch changeset, with no new public API (verified; the built API surface shows no change).
  • Description: the focused tests, build, typecheck, formatting and lint checks pass (verified locally and by CI's lint run).
  • Files: .changeset/nearest-theme-icons.md, packages/core/src/Icon/Icon.tsx, packages/core/src/Icon/useIcon.ts, packages/core/src/Icon/nearestTheme.test.tsx: clear.

Automated review (maintainer link)

@cixzhang
cixzhang merged commit 8439a11 into meta:main Nov 13, 2026
145 of 153 checks passed
@github-actions
github-actions Bot deleted the korkt-kim/ast087-nearest-theme-icons branch November 14, 2026 12:35

This branch was successfully deployed

1 active deployment
Preview — 5cbd35da Deployed Nov 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants