Skip to content

feat(core): drop 'use client' from server-safe primitives - #4407

Merged
imdreamrunner merged 4 commits into
meta:mainfrom
AKnassa:ak-823-rsc-use-client
Aug 14, 2026
Merged

imdreamrunner merged 4 commits into
meta:mainfrom
AKnassa:ak-823-rsc-use-client

Conversation

@AKnassa

@AKnassa AKnassa commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

What this does

Marks 10 simple presentational components as safe to render on the server, by removing their 'use client' directive.

Why

It's Phase 1 of the issue, written there verbatim: "Remove use client from Tier 1 source files."

The Tier 1 list in the issue is four months stale

Copying it would have stripped the directive off components that genuinely need it:

Component Why it must keep the directive
Kbd useSyncExternalStore
ProgressBar useId
Divider useId — labeled dividers gained it upstream (#4370) while this PR was open
Field reaches LinkContext (createContext) through Button
OverflowList useOverflow — useState, useCallback, useRef
StatusDot imports Tooltip
Icon module-level registry, mutated by the public registerIcons()

So the set here is derived from the actual import graph instead. All 8 obvious candidates confirmed, and three components on no list at all qualify: Blockquote, Code, VisuallyHidden. Divider was originally in the dropped set; the rebase brought in #4370 and the guard flagged it, so it moves to the table above under the same rule as ProgressBar.

How the set was derived

The first classifier flagged every candidate and every already-shipped directive-free component as unsafe. Since those ship without the directive today, the model was wrong, not the ground truth. The fix: sideEffects in package.json is a narrow allowlist, so every other module is drop-eligible and traversal must follow pure barrels by used export. Under that model the classifier reproduces the repo's existing directive-free set exactly — that agreement is the calibration proof. Parsing goes through the TypeScript compiler API so type-only imports erase correctly.

The guard, and why the existing script didn't catch this

The new test derives the safe set from the import graph rather than restating it. That matters: adding import {Tooltip} to Badge.tsx leaves scripts/check-use-client.mjs passing, because it only checks direct React client APIs.

Review round: both synchronized CLIENT_APIS lists were missing React 19's useActionState, useEffectEvent and startTransition — the full set of exports react's own react-server build omits. All three are covered now, and two meta-guards close the class: the client-only set is checked against react's builds (a future client-only hook fails the test on its own), and the two lists are asserted identical so they cannot drift apart.

The orphan status originally reported here has since been fixed on main — check:repo now runs the script in lint and pre-commit, so the direct-import direction is CI-enforced. The transitive direction ships with this PR's test.

Honest framing

This unblocks Phase 2; it does not ship RSC support. Without the react-server export condition the export map still has a single path, so no consumer sees a difference yet.

Not breaking: no prop, type or export changed, and the directive is inert outside an RSC bundler. Bundle layout can shift for existing client consumers — these are no longer client chunk boundaries, so they may inline into importing chunks rather than dedupe as shared entries. No behaviour change, size diffs possible either direction.

How to check

pnpm vitest run packages/core/src/serverSafeComponents.test.ts → 18 tests: the parse rules, the react-build ground truth, list sync, and both invariants across every public component subpath. node scripts/check-use-client.mjs → 234 files, exit 0. Core typecheck clean. An earlier round verified the emitted dist/ boundaries (targets stripped, keepers retained); the full suite runs in CI on the current head.

Refs #823

@vercel

vercel Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 14, 2026 5:02am

Request Review

@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 Jul 26, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 26, 2026
@github-actions

github-actions Bot commented Jul 26, 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

AspectRatio (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 83 -
Complexity N/A Low (3) -
Badge (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 175 -
Complexity N/A Low (1) -
Blockquote (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 62 -
Complexity N/A Low (2) -
Card (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 201 -
Complexity N/A High (18) -
Center (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 99 -
Complexity N/A Medium (14) -
Code (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 81 -
Complexity N/A Low (2) -
Grid (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 347 -
Complexity N/A Very High (35) -
Section (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 195 -
Complexity N/A Very High (32) -
Skeleton (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 112 -
Complexity N/A Low (3) -
VisuallyHidden (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 47 -
Complexity N/A Low (2) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 1.2KB

Accessibility Audit

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

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

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

@AKnassa

AKnassa commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor Author

These four are pre-existing on main. This PR deletes 'use client' lines and adds a test. It changes no token, style rule or markup.

pr-a11y has no baseline. It builds only the head Storybook (ci.yml:448-453), records every violation axe finds (accessibility-audit.js:176-186), and enrols a component when any file in its folder changed (analyze-pr.js:425-439). The same ratios appear on #4117, #4155, #4162, #4207, #4283, #4296 and #4349: Badge 2/5, Grid 2/12, Section 2/7, Card 8/14.

Card, Grid and Section are caption text in the story files, not component markup. All three are --color-text-secondary #737373 on the Storybook body #f1f1f1, which is 4.20:1. It passes on white at 4.74:1, so only some stories trip. #3677 fixes it by moving the token to #616161 (5.48:1), and its audit reports Card clean.

Badge is real and separate. variant="error" computes #ffffff on #e33f4a, 4.14:1 at 12px/500. The Badge block re-binds --color-error to #e33f4a (neutralTheme.ts:605-607) while --color-on-error stays white. #c9303a would give 5.29:1. Not fixed by #3677. Filed as #4414.

Unrelated suggestion: accessibility-audit.js:228-234 drops axe's failureSummary, so these reports can never show the measured colours or ratio.

@AKnassa

AKnassa commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

ProgressBar belongs in this set. React 19.2.7's react-server entry exports useId, useMemo and useCallback, so those three do not belong in CLIENT_APIS. useId is ProgressBar's only React import (ProgressBar.tsx:19), used for aria-labelledby, and this PR clears its last blocker by freeing VisuallyHidden. As written, serverSafeComponents.test.ts will now fail anyone who removes its directive. Same question for AvatarGroup, ButtonGroup, FormLayout, InputGroup, Layout, RadioList, SegmentedControl and Toolbar, whose only direct client APIs are also useId, useMemo or useCallback.

Two fixes for the description. "No consumer sees a difference yet" is too strong: the directive is read from file contents, not the export map, so an RSC consumer importing Badge loses its client boundary as soon as this lands. And the sideEffects list also includes **/*.stylex.js.

@cixzhang

Copy link
Copy Markdown
Contributor

@imdreamrunner — could you take this one? You're already on the reviewer list; I'd like your call specifically rather than mine.

Why you: it's an RSC-correctness change across 11 components, and the failure mode is silent — a directive removed from something that actually needs client behavior doesn't fail a test, it fails in a consumer's server render. T30 is a blocking check whose enforcer (scripts/check-use-client.mjs) isn't wired into any npm script or workflow, so CI green means nothing here and the review is the only gate.

The part worth your attention is the method rather than the list: the issue's Tier 1 list was four months stale, so @AKnassa derived the set from the actual import graph instead and documented six components that must keep the directive (Kbd, ProgressBar, Field, OverflowList, StatusDot, Icon). If that derivation is sound the rest follows; if it missed a transitive client import, we ship a broken server render.

@AKnassa — it's 387 commits behind main and currently conflicting, so it needs a rebase before a review can mean much. Would you mind bringing it up to date? Sorry it sat this long.

Phase 1 of the RSC issue, as written there: remove the directive from
components that import no client-only surface. The Tier 1 list in the issue
is four months stale and now wrong — Kbd and ProgressBar reach React client
APIs, Field reaches LinkContext through Button, OverflowList imports
useOverflow, StatusDot imports Tooltip — so the set here is derived from the
import graph instead, and three components on no list at all (Blockquote,
Code, VisuallyHidden) qualify.

Traversal follows pure barrels by used export, because `sideEffects` in
package.json is a narrow allowlist and every other module is drop-eligible.
The calibration is that the classifier reproduces the repo's existing
directive-free set exactly; a naive whole-barrel walk instead flagged those
same shipped components as unsafe, which is how the model was caught wrong.

Icon is deliberately kept. It reaches no React client API, so a hooks-only
rule would strip it — but its module-level registry is mutated by the public
`registerIcons()`, and on a server that is state shared across requests
diverging silently from the client's copy.

The new test derives the safe set from the graph rather than restating it.
That matters: `scripts/check-use-client.mjs` passes when a client-only
component is imported transitively, and it is an orphan besides — nothing in
package.json, check:repo, lint or any workflow invokes it, which is plausibly
how the Tier 1 list drifted unnoticed.

This unblocks Phase 2 rather than shipping RSC support; without the
`react-server` export condition no consumer sees any change.

Refs meta#823
The guard added in this PR had two false negatives, both mutation-proven:
a component reaching a React client API through either route was reported
server-safe, which is exactly the failure it exists to prevent.

1. A namespace or default binding was invisible. The react scan was gated
   on ts.isNamedImports, so only `import {useState} from 'react'` was seen.
   `theme/Theme.tsx:91` already does `React.createContext(false)`, and 56
   non-test files bind React by default import. Now the local binding name
   is recorded and swept for value-position property accesses. Type
   references (`React.ReactNode`) parse as QualifiedName rather than
   PropertyAccessExpression, so they still do not match.

2. `use` was missing from CLIENT_APIS. The package has migrated to React
   19's `use()` for context reads; ten source files import it and no other
   listed API. It did not fire only because every call site also pulled a
   module containing createContext — the producer was detected, never the
   consumer. Both gaps met in theme/Theme.tsx, which was classified right
   only by three unrelated hooks sharing its import line.

Also: walk past every string-literal directive rather than breaking on the
first non-`use client` one, so a `'use strict';` prologue cannot hide the
directive behind it (theme/syntax/defineSyntaxTheme.ts:3 has that shape);
raise the entry-point floor from 50 to 95 against a real count of 104, so a
resolution bug cannot silently turn both invariants into no-ops; and credit
the changeset to its actual author.

The detection rules are now split into parseSource() and unit-tested against
source strings, mirroring theme/themingTargets.test.ts.

`use` is over-approximate — `use(promise)` is legal on the server — but every
call site in this package reads a context, which is as client-only as
useContext. Noted in both lists.

Verified: 11/11 in the guard, 221 files clean in check-use-client.mjs
(up from 210), eslint clean under CI=true, prettier clean, changeset gate
passes. Both must-fixes re-confirmed by mutation against the graph walk.
@AKnassa
AKnassa force-pushed the ak-823-rsc-use-client branch from d4e68d2 to 470732e Compare August 14, 2026 03:52
@AKnassa

AKnassa commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main and mergeable again. Conflicts were only the Badge, Divider and Section barrels where the VariantMap interfaces moved in; the directive set is unchanged, and the two components added since (ComplexSelector, Indicator) both reach client surfaces, so the derived set holds.

@imdreamrunner imdreamrunner 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.

The 11 existing 'use client' removals look safe, including their component barrels, and the emitted distribution preserves those boundaries correctly.

One blocker remains: the synchronized CLIENT_APIS lists omit React 19 client-only APIs including useActionState and useEffectEvent. Adding an unconditional useActionState() call to directive-free Badge left both guards green, while a Next RSC build correctly failed because the API requires a client boundary.

Please cover the missing APIs in both classifiers and add a regression test. This does not invalidate the current removals; it ensures the new guard catches future regressions.

github-actions Bot added a commit that referenced this pull request Aug 14, 2026
meta#823)

startTransition is the third react-server omission alongside the
useActionState/useEffectEvent pair covered in 4324f41; add it to both
classifiers. Two meta-guards close the drift class: the client-only set is
checked against react's own builds, so a future client-only hook fails the
test on its own, and the two CLIENT_APIS lists are asserted identical.
Aliased and namespace-access imports of the new APIs get parse tests.
@AKnassa

AKnassa commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for 4324f41. startTransition turned out to be a third omission; both classifiers now carry all three (be4754f), with parse tests for named, aliased and namespace-access imports. Two meta-guards close the drift class: the client-only set is now checked against react's own react-server build, so a future client-only hook fails the test on its own, and the two lists are asserted identical. Body updated for the Divider move and the dropped count of 10.

@imdreamrunner
imdreamrunner enabled auto-merge (squash) August 14, 2026 05:28
@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Aug 14, 2026
@imdreamrunner
imdreamrunner merged commit 647ff7e into meta:main Aug 14, 2026
21 checks passed
@imdreamrunner

Copy link
Copy Markdown
Contributor

Thanks for improving this!

@github-actions
github-actions Bot deleted the ak-823-rsc-use-client branch August 14, 2026 07:20
cixzhang added a commit that referenced this pull request Aug 21, 2026
…, wrap long words (#5144)

* fix(Blockquote): drop the contentinfo landmark from the attribution

<blockquote> is a sectioning root rather than sectioning content, so the
<footer> that wrapped the cite attribution mapped to a contentinfo document
landmark. Three quotes on a page produced three of them, and axe reports
landmark-no-duplicate-contentinfo and landmark-unique against Blockquote's
own footer as soon as the page carries any other landmark. The repo's own
BlockquoteTestimonials block ships three quotes. Render the <cite> directly.

Two smaller fixes in the same file: guard the slot with isRenderable, so
cite={condition && author} and cite="" stop emitting an empty <cite> element
(@astryx/no-nullish-jsx-guard already flagged the bare != null check), and
set overflow-wrap: break-word so a long unbroken word or URL wraps instead of
overflowing its own box at narrow widths.

Adds a server render test: #4407 removed 'use client' from this file and
nothing asserted that it still renders through react-dom/server.

* docs(Blockquote): correct the described visuals and fill the doc gaps

The overview described an "accent-colored left border". The rule is drawn
with --color-border-emphasized, which is a neutral border token rather than
an accent, and it is a logical inline-start border that moves to the right
edge in right-to-left locales. Corrected in the English, Chinese and dense
docs and in the component JSDoc.

Adds the pieces the doc conventions ask for and this file was missing:
usage.anatomy, a second "don't", accessibility guidance in bestPractices,
and playground.defaults so the playground does not open blank on a component
whose children are required.

Stories: adds a pull-quote story that exercises xstyle (the only documented
prop no story touched), a long-content story covering wrapped quotes, long
attributions and an unbroken URL, and a narrow-container story. The a11y and
RTL sweeps only see what a story renders.

This branch was successfully deployed

1 active deployment
Preview — be4754f1 Deployed Aug 14, 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. 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.

3 participants