Repository navigation
feat(core): drop 'use client' from server-safe primitives - #4407
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsAspectRatio (@astryxdesign/core) · View in Storybook
Badge (@astryxdesign/core) · View in Storybook
Blockquote (@astryxdesign/core) · View in Storybook
Card (@astryxdesign/core) · View in Storybook
Center (@astryxdesign/core) · View in Storybook
Code (@astryxdesign/core) · View in Storybook
Grid (@astryxdesign/core) · View in Storybook
Section (@astryxdesign/core) · View in Storybook
Skeleton (@astryxdesign/core) · View in Storybook
VisuallyHidden (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. Badge - 1 issue(s)
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
|
These four are pre-existing on
Card, Grid and Section are caption text in the story files, not component markup. All three are Badge is real and separate. Unrelated suggestion: |
|
ProgressBar belongs in this set. React 19.2.7's 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 |
|
@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. 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 ( @AKnassa — it's 387 commits behind |
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.
d4e68d2 to
470732e
Compare
|
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
left a comment
There was a problem hiding this comment.
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.
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.
|
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. |
|
Thanks for improving this! |
…, 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.
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 clientfrom 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:
KbduseSyncExternalStoreProgressBaruseIdDivideruseId— labeled dividers gained it upstream (#4370) while this PR was openFieldLinkContext(createContext) throughButtonOverflowListuseOverflow—useState,useCallback,useRefStatusDotTooltipIconregisterIcons()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:
sideEffectsinpackage.jsonis 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}toBadge.tsxleavesscripts/check-use-client.mjspassing, because it only checks direct React client APIs.Review round: both synchronized
CLIENT_APISlists were missing React 19'suseActionState,useEffectEventandstartTransition— the full set of exports react's ownreact-serverbuild 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:reponow 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-serverexport 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 emitteddist/boundaries (targets stripped, keepers retained); the full suite runs in CI on the current head.Refs #823