Skip to content

fix: add missing 'use client' directives - #812

Merged
cixzhang merged 1 commit into
mainfrom
navi/fix/use-client-directives
Mar 22, 2026
Merged

cixzhang merged 1 commit into
mainfrom
navi/fix/use-client-directives

Conversation

@cixzhang

@cixzhang cixzhang commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds 'use client' directive to 10 source files that use React client hooks but were missing it. When tsup bundles these into shared chunks for the dist path, the missing directive causes Next.js builds to fail with createContext only works in a Client Component.

Found by scanning all packages/core/src/ files for React client API imports without a corresponding 'use client' directive.

Files fixed

  • PowerSearch/useInternalConfig.ts — useMemo
  • PowerSearch/usePowerSearchConfig.ts — useMemo
  • PowerSearch/usePowerSearchSource.ts — useMemo
  • SideNav/XDSSideNavCollapseContext.ts — createContext, useContext
  • SideNav/XDSSideNavRenderContext.ts — createContext, useContext
  • SideNav/useResizable.ts — useState, useEffect, useRef, useCallback
  • TopNav/TopNavContext.ts — createContext, useContext
  • TopNav/XDSTopNavMenu.tsx — useState, useEffect, useRef, useCallback, useId
  • TopNav/XDSTopNavMobileContentContext.ts — createContext, useContext
  • TopNav/XDSTopNavRenderContext.ts — createContext, useContext

Fixes the sandbox build failure in #806.


Add 'use client' directive to 10 source files that use React client
hooks (createContext, useContext, useState, etc.) but were missing it.

When tsup bundles these into shared chunks for the dist path, the
missing directive causes Next.js builds to fail with 'createContext
only works in a Client Component'.

Files fixed:
- PowerSearch/useInternalConfig.ts
- PowerSearch/usePowerSearchConfig.ts
- PowerSearch/usePowerSearchSource.ts
- SideNav/XDSSideNavCollapseContext.ts
- SideNav/XDSSideNavRenderContext.ts
- SideNav/useResizable.ts
- TopNav/TopNavContext.ts
- TopNav/XDSTopNavMenu.tsx
- TopNav/XDSTopNavMobileContentContext.ts
- TopNav/XDSTopNavRenderContext.ts
@cixzhang
cixzhang requested a review from josephfarina as a code owner March 22, 2026 04:04
@cixzhang cixzhang added the bug Something isn't working label Mar 22, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 22, 2026
@cixzhang
cixzhang merged commit c61703f into main Mar 22, 2026
10 checks passed
@github-actions

github-actions Bot commented Mar 22, 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

PowerSearch · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 1.5KB N/A
Lines of Code N/A 3045 -
Complexity N/A Very High (296) -
SideNav · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 1.2KB N/A
Lines of Code N/A 1491 -
Complexity N/A Very High (146) -
TopNav · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 1.2KB N/A
Lines of Code N/A 1512 -
Complexity N/A Very High (92) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 11.0KB 17.5KB 2.7KB

Accessibility Audit

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

XDSSideNav - 1 issue(s)
  • 🟠 serious: Ensure links have discernible text
    • Rule: link-name · Affects 1/8 stories · Learn more
    • WCAG: 2.4.4, 4.1.2 (Level A)

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

cixzhang pushed a commit that referenced this pull request Mar 22, 2026
Add 'use client' to all 95 source files using React client APIs.
This ensures tsup shared chunks can preserve the directive (tsup
only propagates it when ALL files in a chunk have it).

Also adds scripts/check-use-client.mjs — a CI check that verifies
all source files using client APIs have the directive.

Files from original list (87): 85 needed the directive, 2 already
had it from PR #812. Found 10 additional files that were also
missing it (SegmentedControl, TreeList, SideNav, Selector/hooks,
AppShell/MobileContext, hooks/useOverflow).

Note: CI workflow integration deferred — requires workflow scope
token. Run 'node scripts/check-use-client.mjs' after build.
cixzhang added a commit that referenced this pull request Mar 22, 2026
* fix: comprehensive 'use client' directives + source check

Add 'use client' to all 95 source files using React client APIs.
This ensures tsup shared chunks can preserve the directive (tsup
only propagates it when ALL files in a chunk have it).

Also adds scripts/check-use-client.mjs — a CI check that verifies
all source files using client APIs have the directive.

Files from original list (87): 85 needed the directive, 2 already
had it from PR #812. Found 10 additional files that were also
missing it (SegmentedControl, TreeList, SideNav, Selector/hooks,
AppShell/MobileContext, hooks/useOverflow).

Note: CI workflow integration deferred — requires workflow scope
token. Run 'node scripts/check-use-client.mjs' after build.

* fix: splitting: false + clean up duplicate use client directives

* fix: restore XDSAppShell.tsx (accidentally emptied during cleanup)

---------

Co-authored-by: Navi <[email protected]>
@cixzhang
cixzhang deleted the navi/fix/use-client-directives branch April 9, 2026 14:33
cixzhang added a commit that referenced this pull request Apr 26, 2026
* fix: comprehensive 'use client' directives + source check

Add 'use client' to all 95 source files using React client APIs.
This ensures tsup shared chunks can preserve the directive (tsup
only propagates it when ALL files in a chunk have it).

Also adds scripts/check-use-client.mjs — a CI check that verifies
all source files using client APIs have the directive.

Files from original list (87): 85 needed the directive, 2 already
had it from PR #812. Found 10 additional files that were also
missing it (SegmentedControl, TreeList, SideNav, Selector/hooks,
AppShell/MobileContext, hooks/useOverflow).

Note: CI workflow integration deferred — requires workflow scope
token. Run 'node scripts/check-use-client.mjs' after build.

* fix: splitting: false + clean up duplicate use client directives

* fix: restore XDSAppShell.tsx (accidentally emptied during cleanup)

---------

Co-authored-by: Navi <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
* fix: comprehensive 'use client' directives + source check

Add 'use client' to all 95 source files using React client APIs.
This ensures tsup shared chunks can preserve the directive (tsup
only propagates it when ALL files in a chunk have it).

Also adds scripts/check-use-client.mjs — a CI check that verifies
all source files using client APIs have the directive.

Files from original list (87): 85 needed the directive, 2 already
had it from PR #812. Found 10 additional files that were also
missing it (SegmentedControl, TreeList, SideNav, Selector/hooks,
AppShell/MobileContext, hooks/useOverflow).

Note: CI workflow integration deferred — requires workflow scope
token. Run 'node scripts/check-use-client.mjs' after build.

* fix: splitting: false + clean up duplicate use client directives

* fix: restore XDSAppShell.tsx (accidentally emptied during cleanup)

---------

Co-authored-by: Navi <[email protected]>
cixzhang added a commit that referenced this pull request Jun 21, 2026
* fix: comprehensive 'use client' directives + source check

Add 'use client' to all 95 source files using React client APIs.
This ensures tsup shared chunks can preserve the directive (tsup
only propagates it when ALL files in a chunk have it).

Also adds scripts/check-use-client.mjs — a CI check that verifies
all source files using client APIs have the directive.

Files from original list (87): 85 needed the directive, 2 already
had it from PR #812. Found 10 additional files that were also
missing it (SegmentedControl, TreeList, SideNav, Selector/hooks,
AppShell/MobileContext, hooks/useOverflow).

Note: CI workflow integration deferred — requires workflow scope
token. Run 'node scripts/check-use-client.mjs' after build.

* fix: splitting: false + clean up duplicate use client directives

* fix: restore XDSAppShell.tsx (accidentally emptied during cleanup)

---------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working 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