Add RSC 'use client' directive to main package entrypoint#1285
Conversation
🦋 Changeset detectedLatest commit: e159134 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🟢 No design token changes found |
🟢 No unit test coverage changes foundAll components and hooks with tests maintain the same coverage as the main branch. |
|
There was a problem hiding this comment.
Pull request overview
This PR updates the @primer/react-brand build and test setup to better support React Server Components (RSC) consumers (e.g. Next.js App Router) by ensuring the published entry bundle is treated as a Client Component.
Changes:
- Add
'use client'to the package TypeScript entrypoint (packages/react/src/index.ts). - Add a custom webpack plugin to prepend
'use client'to the emitted UMD bundle (packages/react/webpack.config.js). - Adjust the Next.js e2e integration fixture/component boundary and add a changeset describing the behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react/webpack.config.js | Prepends 'use client' to the generated UMD index.js to keep the directive at the top of the emitted asset. |
| packages/react/src/index.ts | Marks the public barrel entrypoint as a client module. |
| packages/e2e/integration-tests/nextjs/page.tsx | Removes 'use client' from the page to allow server-page → client-fixture composition. |
| packages/e2e/integration-tests/fixtures/KitchenSink.tsx | Adds 'use client' to the fixture component (it uses hooks). |
| .changeset/sunny-sails-invite.md | Release note for the RSC/client-entrypoint change. |
You can also share your feedback on Copilot code review. Take the survey.
|
LGTM! 🚀 |

Summary
Towards https://github.com/github/brand-experience/issues/80
Improves React Server Component (RSC) interop for modern UI frameworks like Next.js.
Previously, users importing library components would need to manually add the
use clientdirective to all React pages/components that used Primer Brand. This caused friction and concern.Now the library includes the relevant fixes to ensure that such user intervention is no longer required. The now include the required directives that enable smoother, frictionless interop. The approach taken is the same as other popular React UI component libraries, which pass through the directive at a library level.
Note
There is a separate RSC-specific error that appears for components that use the dot-notation, compound pattern API. These are not addressed in this PR and will require a separate update.
List of notable changes:
use clientdirective to library entrypointsSteps to test:
@primer/react-brandon a new Next.js installationSupporting resources (related issues, external links, etc):
Contributor checklist:
update snapshotslabel to the PR)Reviewer checklist:
Screenshots: