-
Notifications
You must be signed in to change notification settings - Fork 56
Upgrade to React v19 #1195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade to React v19 #1195
Conversation
🦋 Changeset detectedLatest commit: a8a497c The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR upgrades the Primer Brand monorepo to React v19 as the default version while maintaining backwards compatibility with React v18. The primary changes involve improved type safety for React elements, better ref handling, and removal of deprecated patterns.
Key changes:
- Upgraded React and React types to v19 across main packages (react, e2e, storybook, design-tokens, css)
- Improved type assertions on
React.isValidElementandReact.cloneElementcalls throughout component tree - Enhanced ref forwarding patterns to comply with React 19's stricter type requirements
- Replaced
react-isFragment detection with customisFragmentElementutility - Updated
inertattribute handling in RiverAccordion (now boolean instead of string) - Configured separate tsconfig files for tests and builds with appropriate type inclusions
- Excluded next-docs from workspace (downgraded to React 18 due to dependencies)
Reviewed changes
Copilot reviewed 77 out of 80 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/react/package.json | Updated React types to v19, added @types/chai and @types/node dependencies |
| packages/react/tsconfig.json | Added dom.iterable lib and explicit types array for improved type resolution |
| packages/react/tsconfig.test.json | New test-specific config with jest types included |
| packages/react/tsconfig.build.json | Expanded build exclusions to cover all test file patterns |
| packages/react/src/react-jsx.d.ts | New JSX namespace declaration for React 19 runtime compatibility |
| packages/react/src/utils/isFragmentElement.ts | Custom Fragment type guard replacing react-is dependency |
| packages/react/src/river/RiverAccordion/RiverAccordion.tsx | Updated inert attribute to boolean with proper type assertion |
| packages/react/src/river/River/River.tsx | Moved ref prop before other props, added type parameters to isValidElement |
| packages/react/src/hooks/*.ts | Enhanced ref type signatures to explicitly include null |
| packages/react/src/forms/*.tsx | Improved type safety with explicit component prop types |
| packages/react/src//.tsx | Systematic improvements to React.isValidElement and cloneElement type parameters across 40+ components |
| packages/react/jest.config.js | Added ts-jest transform with tsconfig.test.json for proper test type resolution |
| packages/e2e/, packages/design-tokens/, packages/css/** | Added @types/node and updated tsconfig to include node types |
| package.json | Upgraded React to 19.2.0, added postinstall hook for next-docs, excluded next-docs from workspace |
| apps/storybook/package.json | Updated React and React types to v19 |
| apps/next-docs/package.json | Pinned to React 18 types with overrides for compatibility |
| .changeset/hungry-readers-switch.md | Documented breaking and non-breaking changes |
🟢 No visual differences foundOur visual comparison tests did not find any differences in the UI. |
🟢 Unit test coverage changes foundUnit test coverage has been updated through this PR. Changes: 0 new tests, 0 removed tests, 6 improved, 13 decreased
|
danielguillan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Summary
Towards https://github.com/github/primer/issues/6134
Improves support for React 19, which is now the default React version for all monorepo packages except Docs.
List of notable changes:
refas props support for multiple components (see changeset), which are treated differently inv19@types/react-*@v19by default@primer/reactand@primer/doctocat-nextjsto supportv19first 🔁pagecontainer was being reassigned too early. While this also happened before this PR, the workaround of restarting the workflow no longer works.ℹ️ There should not be any functional or presentational changes in this PR. Changes should also remain backwards compatible with React@v18.
Any drops in test coverage are due to additional LoC for null
refsupport. These can be reviewed in follow-up PR's individually. We have sufficient test coverage forrefin most components now.What should reviewers focus on?
Steps to test:
Supporting resources (related issues, external links, etc):
Contributor checklist:
update snapshotslabel to the PR)Reviewer checklist:
Screenshots:
N/A 🤞