Repository navigation
test: add React Server Component test support via vitest-plugin-rsc - #8813
tay1orjones wants to merge 3 commits into
Conversation
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
|
|
There was a problem hiding this comment.
🟡 Changes recommended
The new RSC suite fails CI’s className coverage check, and its checkbox assertions can pass even when React’s client-side interaction handling is broken.
2 open issues
What changed in this PR
Adds React Server Component testing to Primer React through vitest-plugin-rsc, using a separate browser-based Vitest project enabled on React 19.
Changes:
- Registers the RSC project and excludes its tests from the existing browser suite.
- Adds setup hooks and examples for server rendering and client interaction.
- Documents the test environment and adds the required development dependency.
| File | Description |
|---|---|
vitest.config.mts |
Registers RSC test projects. |
packages/react/vitest.config.rsc.mts |
Configures React 19-gated RSC tests in Chromium. |
packages/react/vitest.config.browser.mts |
Excludes RSC tests from the standard browser suite. |
packages/react/tsconfig.json |
Includes the RSC configuration in type checking. |
packages/react/src/__tests__/components.rsc.test.tsx |
Adds rendering and interaction examples. |
packages/react/package.json |
Adds vitest-plugin-rsc as a development dependency. |
packages/react/config/vitest/rsc/setup.ts |
Initializes and cleans up the RSC test environment. |
package-lock.json |
Records the plugin and dependency updates. |
contributor-docs/testing.md |
Documents RSC tests and the React 19 requirement. |
Review effort: Balanced
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>


Fixes #8451
Adds React Server Component test support to
packages/reactusingvitest-plugin-rsc, with two example tests.Note: the plugin renders the server and client environments inside the test's browser tab, so it cannot run in the Node project next to
ssr.test.tsx. It lives in its own Vitest project instead (@primer/react (rsc)), and*.rsc.test.tsxis excluded from the existing Chromium project, which is otherwise unchanged. The plugin's non-Next mode is used, so nonextconfig is needed. Thenext/@next/routingpeers are only auto-installed by npm.Changelog
New
vitest.config.rsc.mtsVitest project, setup file, andsrc/__tests__/components.rsc.test.tsx(components render inside a Server Component; client components behind the'use client'entry hydrate and respond to interaction)contributor-docs/testing.mdChanged
vitest.config.mtsregisters the new project; browser project excludes*.rsc.test.tsxRemoved
N/A
Rollout strategy
Testing & Reviewing
Server Components need React 19, and the repo installs React 18 by default. The rsc project therefore has no tests on React 18 and runs in the existing React 19 CI job. Verified locally with
node script/setup-react-19.mtsthennpx vitest run --project '@primer/react (rsc)'(2 passed), and the fullnpx vitest runon React 18 (no new failures;@primer/mcpand@primer/styled-reactfail only because packages aren't built here).