Skip to content

refactor(icons): migrate components from useXDSIcon to getIcon - #531

Merged
cixzhang merged 1 commit into
mainfrom
navi/feat/migrate-to-getIcon
Mar 8, 2026
Merged

cixzhang merged 1 commit into
mainfrom
navi/feat/migrate-to-getIcon

Conversation

@cixzhang

@cixzhang cixzhang commented Mar 8, 2026 •

Copy link
Copy Markdown
Contributor

What

Migrates all internal component icon resolution from useXDSIcon() (React Context hook) to getIcon() (module-level function from the global registry). This establishes a single path for icon resolution that works in both server and client environments.

Follows up on #528 which added registerIcons() and getIcon().

Why

useXDSIcon() requires React Context (IconRegistryContext) which only works client-side. With RSC adoption, components need icons without hooks. getIcon() reads from module-level state — no Context, no hooks, works everywhere.

Changes

Components migrated (3 files)

  • XDSIcon.tsx — IconFromRegistry now calls getIcon(name) instead of useXDSIcon(name)
  • XDSCollapsible.tsx — chevron icon via getIcon('chevronDown')
  • XDSMoreMenu.tsx — more icon via getIcon('moreHorizontal')

Theme updated (1 file)

  • XDSTheme.tsx — Removed IconRegistryContext.Provider wrapper. Icons are now set globally via registerIcons(icons) only. No Context needed.

Deprecated (1 file)

  • IconRegistry.tsx — useXDSIcon and IconRegistryContext marked @deprecated with JSDoc. Kept exported for backward compatibility.

Exports updated (1 file)

  • Icon/index.ts — deprecated exports annotated with JSDoc comment

Docs updated (1 file)

  • globalIconRegistry.tsx — updated comments to reflect it's now the single icon resolution path

Verification

  • ✅ yarn build — passes
  • ✅ yarn test — 1390 tests pass
  • ✅ yarn lint — 0 errors (pre-existing warnings only)
  • ✅ No component imports useXDSIcon (only the deprecated export itself)

Replace all component-level useXDSIcon() calls with getIcon() from the
global icon registry. This removes the React Context dependency for icon
resolution, making icons work in both server and client environments.

Changes:
- XDSIcon: use getIcon() instead of useXDSIcon()
- XDSCollapsible: use getIcon() instead of useXDSIcon()
- XDSMoreMenu: use getIcon() instead of useXDSIcon()
- XDSTheme: remove IconRegistryContext.Provider wrapper, keep registerIcons()
- IconRegistry: deprecate useXDSIcon and IconRegistryContext with JSDoc
- globalIconRegistry: update docs to reflect it's the single icon path
- Icon/index.ts: mark deprecated exports with JSDoc
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 8, 2026
@github-actions

github-actions Bot commented Mar 8, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Collapsible · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 4.7KB N/A
Lines of Code N/A 242 -
Complexity N/A High (18) -
Icon · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 367B N/A
Lines of Code N/A 322 -
Complexity N/A Medium (7) -
MoreMenu · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 561B N/A
Lines of Code N/A 367 -
Complexity N/A Very High (49) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 9.2KB 14.9KB 2.3KB

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

XDSIcon - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/16 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Component Previews

Includes interactive hover previews as animated GIFs.

XDSCollapsible

Single Mode (default)

Screenshot:

Single Mode (default)

Interaction Preview: (view video)

Single Mode (default) interaction

View in Storybook · components-xdscollapsible--single-mode

Multiple Mode

Screenshot:

Multiple Mode

View in Storybook · components-xdscollapsible--multiple-mode

Controlled

Screenshot:

Controlled

View in Storybook · components-xdscollapsible--controlled

Standalone Collapsible

Screenshot:

Standalone Collapsible

View in Storybook · components-xdscollapsible--standalone-collapsible

Without Card (standalone)

Screenshot:

Without Card (standalone)

View in Storybook · components-xdscollapsible--without-card

FAQ Page

Screenshot:

FAQ Page

View in Storybook · components-xdscollapsible--faq

XDSIcon

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · core-xdsicon--default

Primary

Screenshot:

Primary

View in Storybook · core-xdsicon--primary

Secondary

Screenshot:

Secondary

View in Storybook · core-xdsicon--secondary

Accent

Screenshot:

Accent

View in Storybook · core-xdsicon--accent

Positive

Screenshot:

Positive

View in Storybook · core-xdsicon--positive

Negative

Screenshot:

Negative

View in Storybook · core-xdsicon--negative

Warning

Screenshot:

Warning

View in Storybook · core-xdsicon--warning

Extra Small

Screenshot:

Extra Small

View in Storybook · core-xdsicon--extra-small

Small

Screenshot:

Small

View in Storybook · core-xdsicon--small

Medium

Screenshot:

Medium

View in Storybook · core-xdsicon--medium

Large

Screenshot:

Large

View in Storybook · core-xdsicon--large

Solid Icon

Screenshot:

Solid Icon

View in Storybook · core-xdsicon--solid-icon

All Colors

Screenshot:

All Colors

View in Storybook · core-xdsicon--all-colors

All Sizes

Screenshot:

All Sizes

View in Storybook · core-xdsicon--all-sizes

Outline Vs Solid

Screenshot:

Outline Vs Solid

View in Storybook · core-xdsicon--outline-vs-solid

Inherit Color

Screenshot:

Inherit Color

View in Storybook · core-xdsicon--inherit-color

XDSMoreMenu

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · core-xdsmoremenu--default

With Icons

Screenshot:

With Icons

View in Storybook · core-xdsmoremenu--with-icons

With Dividers

Screenshot:

With Dividers

View in Storybook · core-xdsmoremenu--with-dividers

With Sections

Screenshot:

With Sections

View in Storybook · core-xdsmoremenu--with-sections

Small Size

Screenshot:

Small Size

View in Storybook · core-xdsmoremenu--small-size

Variants

Screenshot:

Variants

View in Storybook · core-xdsmoremenu--variants

Disabled

Screenshot:

Disabled

View in Storybook · core-xdsmoremenu--disabled

In Toolbar

Screenshot:

In Toolbar

View in Storybook · core-xdsmoremenu--in-toolbar

Custom Item Rendering

Screenshot:

Custom Item Rendering

View in Storybook · core-xdsmoremenu--custom-item-rendering

With Disabled Items

Screenshot:

With Disabled Items

View in Storybook · core-xdsmoremenu--with-disabled-items


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang
cixzhang merged commit c651c13 into main Mar 8, 2026
14 checks passed
cixzhang pushed a commit that referenced this pull request Mar 8, 2026
BREAKING CHANGE: Remove deprecated exports that were replaced in prior PRs.

Removed:
- XDSTopNavTitle, XDSTopNavTitleProps (use XDSTopNavHeading, XDSTopNavHeadingProps)
- XDSSideNavHeader, XDSSideNavHeaderProps (use XDSSideNavHeading, XDSSideNavHeadingProps)
- useXDSIcon hook (use getIcon from globalIconRegistry)
- IconRegistryContext (use registerIcons + getIcon)
- IconRegistry.tsx (deleted — all functionality lives in globalIconRegistry.tsx)
- getGlobalRegistry internal helper (no longer needed)

Added:
- migrate-useXDSIcon-to-getIcon codemod with 11 tests
- Updates internal imports from IconRegistry to globalIconRegistry

Migration codemods exist for all removed APIs:
- rename-topnav-title-to-heading (PR #530)
- rename-sidenav-header-to-heading (PR #530)
- migrate-useXDSIcon-to-getIcon (this PR)

Refs: #527, #530, #531
cixzhang added a commit that referenced this pull request Mar 8, 2026
….2 (#533)

BREAKING CHANGE: Remove deprecated exports that were replaced in prior PRs.

Removed:
- XDSTopNavTitle, XDSTopNavTitleProps (use XDSTopNavHeading, XDSTopNavHeadingProps)
- XDSSideNavHeader, XDSSideNavHeaderProps (use XDSSideNavHeading, XDSSideNavHeadingProps)
- useXDSIcon hook (use getIcon from globalIconRegistry)
- IconRegistryContext (use registerIcons + getIcon)
- IconRegistry.tsx (deleted — all functionality lives in globalIconRegistry.tsx)
- getGlobalRegistry internal helper (no longer needed)

Added:
- migrate-useXDSIcon-to-getIcon codemod with 11 tests
- Updates internal imports from IconRegistry to globalIconRegistry

Migration codemods exist for all removed APIs:
- rename-topnav-title-to-heading (PR #530)
- rename-sidenav-header-to-heading (PR #530)
- migrate-useXDSIcon-to-getIcon (this PR)

Refs: #527, #530, #531

Co-authored-by: navi[bot] <[email protected]>
@cixzhang
cixzhang deleted the navi/feat/migrate-to-getIcon branch March 13, 2026 10:50
cixzhang added a commit that referenced this pull request Apr 26, 2026
Replace all component-level useXDSIcon() calls with getIcon() from the
global icon registry. This removes the React Context dependency for icon
resolution, making icons work in both server and client environments.

Changes:
- XDSIcon: use getIcon() instead of useXDSIcon()
- XDSCollapsible: use getIcon() instead of useXDSIcon()
- XDSMoreMenu: use getIcon() instead of useXDSIcon()
- XDSTheme: remove IconRegistryContext.Provider wrapper, keep registerIcons()
- IconRegistry: deprecate useXDSIcon and IconRegistryContext with JSDoc
- globalIconRegistry: update docs to reflect it's the single icon path
- Icon/index.ts: mark deprecated exports with JSDoc

Co-authored-by: navi[bot] <[email protected]>
cixzhang added a commit that referenced this pull request Apr 26, 2026
….2 (#533)

BREAKING CHANGE: Remove deprecated exports that were replaced in prior PRs.

Removed:
- XDSTopNavTitle, XDSTopNavTitleProps (use XDSTopNavHeading, XDSTopNavHeadingProps)
- XDSSideNavHeader, XDSSideNavHeaderProps (use XDSSideNavHeading, XDSSideNavHeadingProps)
- useXDSIcon hook (use getIcon from globalIconRegistry)
- IconRegistryContext (use registerIcons + getIcon)
- IconRegistry.tsx (deleted — all functionality lives in globalIconRegistry.tsx)
- getGlobalRegistry internal helper (no longer needed)

Added:
- migrate-useXDSIcon-to-getIcon codemod with 11 tests
- Updates internal imports from IconRegistry to globalIconRegistry

Migration codemods exist for all removed APIs:
- rename-topnav-title-to-heading (PR #530)
- rename-sidenav-header-to-heading (PR #530)
- migrate-useXDSIcon-to-getIcon (this PR)

Refs: #527, #530, #531

Co-authored-by: navi[bot] <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
Replace all component-level useXDSIcon() calls with getIcon() from the
global icon registry. This removes the React Context dependency for icon
resolution, making icons work in both server and client environments.

Changes:
- XDSIcon: use getIcon() instead of useXDSIcon()
- XDSCollapsible: use getIcon() instead of useXDSIcon()
- XDSMoreMenu: use getIcon() instead of useXDSIcon()
- XDSTheme: remove IconRegistryContext.Provider wrapper, keep registerIcons()
- IconRegistry: deprecate useXDSIcon and IconRegistryContext with JSDoc
- globalIconRegistry: update docs to reflect it's the single icon path
- Icon/index.ts: mark deprecated exports with JSDoc

Co-authored-by: navi[bot] <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
….2 (#533)

BREAKING CHANGE: Remove deprecated exports that were replaced in prior PRs.

Removed:
- XDSTopNavTitle, XDSTopNavTitleProps (use XDSTopNavHeading, XDSTopNavHeadingProps)
- XDSSideNavHeader, XDSSideNavHeaderProps (use XDSSideNavHeading, XDSSideNavHeadingProps)
- useXDSIcon hook (use getIcon from globalIconRegistry)
- IconRegistryContext (use registerIcons + getIcon)
- IconRegistry.tsx (deleted — all functionality lives in globalIconRegistry.tsx)
- getGlobalRegistry internal helper (no longer needed)

Added:
- migrate-useXDSIcon-to-getIcon codemod with 11 tests
- Updates internal imports from IconRegistry to globalIconRegistry

Migration codemods exist for all removed APIs:
- rename-topnav-title-to-heading (PR #530)
- rename-sidenav-header-to-heading (PR #530)
- migrate-useXDSIcon-to-getIcon (this PR)

Refs: #527, #530, #531

Co-authored-by: navi[bot] <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
Replace all component-level useXDSIcon() calls with getIcon() from the
global icon registry. This removes the React Context dependency for icon
resolution, making icons work in both server and client environments.

Changes:
- XDSIcon: use getIcon() instead of useXDSIcon()
- XDSCollapsible: use getIcon() instead of useXDSIcon()
- XDSMoreMenu: use getIcon() instead of useXDSIcon()
- XDSTheme: remove IconRegistryContext.Provider wrapper, keep registerIcons()
- IconRegistry: deprecate useXDSIcon and IconRegistryContext with JSDoc
- globalIconRegistry: update docs to reflect it's the single icon path
- Icon/index.ts: mark deprecated exports with JSDoc
cixzhang added a commit that referenced this pull request Jun 21, 2026
….2 (#533)

BREAKING CHANGE: Remove deprecated exports that were replaced in prior PRs.

Removed:
- XDSTopNavTitle, XDSTopNavTitleProps (use XDSTopNavHeading, XDSTopNavHeadingProps)
- XDSSideNavHeader, XDSSideNavHeaderProps (use XDSSideNavHeading, XDSSideNavHeadingProps)
- useXDSIcon hook (use getIcon from globalIconRegistry)
- IconRegistryContext (use registerIcons + getIcon)
- IconRegistry.tsx (deleted — all functionality lives in globalIconRegistry.tsx)
- getGlobalRegistry internal helper (no longer needed)

Added:
- migrate-useXDSIcon-to-getIcon codemod with 11 tests
- Updates internal imports from IconRegistry to globalIconRegistry

Migration codemods exist for all removed APIs:
- rename-topnav-title-to-heading (PR #530)
- rename-sidenav-header-to-heading (PR #530)
- migrate-useXDSIcon-to-getIcon (this PR)

Refs: #527, #530, #531
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