Skip to content

Conversation

@rezrah
Copy link
Collaborator

@rezrah rezrah commented Nov 24, 2025

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:

  • Improved ref as props support for multiple components (see changeset), which are treated differently in v19
  • Monorepo now uses (and ships) @types/react-*@v19 by default
  • Documentation site downgraded to 18 and excluded as a workspace package as it has a dependency on both @primer/react and @primer/doctocat-nextjs to support v19 first 🔁
  • Unwound many instances of forced type assertions in favour of type narrowing predicates and parameterized generics
  • Fixed a race condition in our AXE tests whereby page container 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 ref support. These can be reviewed in follow-up PR's individually. We have sufficient test coverage for ref in most components now.

What should reviewers focus on?

  • Verify that no visual changes have occured (0 snapshot diffs)

Steps to test:

  1. Verify that no visual changes have occured (0 snapshot diffs / No visual changes comment in this PR)
  2. Go through Storybook preview and check all examples are loading correctly
  3. Go through Docs preview and check all examples are loading correctly

Supporting resources (related issues, external links, etc):

Contributor checklist:

  • All new and existing CI checks pass
  • Tests prove that the feature works and covers both happy and unhappy paths
  • Any drop in coverage, breaking changes or regressions have been documented above
  • UI Changes contain new visual snapshots (generated by adding update snapshots label to the PR)
  • All developer debugging and non-functional logging has been removed
  • Related issues have been referenced in the PR description

Reviewer checklist:

  • Check that pull request and proposed changes adhere to our contribution guidelines and code of conduct
  • Check that tests prove the feature works and covers both happy and unhappy paths
  • Check that there aren't other open Pull Requests for the same update/change

Screenshots:

N/A 🤞

Copilot AI review requested due to automatic review settings November 24, 2025 10:10
@rezrah rezrah requested a review from a team as a code owner November 24, 2025 10:10
@changeset-bot
Copy link

changeset-bot bot commented Nov 24, 2025

🦋 Changeset detected

Latest commit: a8a497c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@primer/react-brand Minor
@primer/brand-css Minor
@primer/brand-primitives Minor
@primer/brand-e2e Minor
@primer/brand-fonts Minor
@primer/brand-config Minor
@primer/brand-storybook Minor

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

@github-actions
Copy link
Contributor

github-actions bot commented Nov 24, 2025

🟢 No design token changes found

Copy link

Copilot AI left a 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.isValidElement and React.cloneElement calls throughout component tree
  • Enhanced ref forwarding patterns to comply with React 19's stricter type requirements
  • Replaced react-is Fragment detection with custom isFragmentElement utility
  • Updated inert attribute 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

@github-actions
Copy link
Contributor

github-actions bot commented Nov 24, 2025

🟢 No visual differences found

Our visual comparison tests did not find any differences in the UI.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 24, 2025

🟢 Unit test coverage changes found

Unit test coverage has been updated through this PR.

Changes: 0 new tests, 0 removed tests, 6 improved, 13 decreased

Component/Hook Statements Functions Branches Change
ButtonGroup 100.0% 88.9% 100.0% 100.0% -11.1%
VideoPlayer 100.0% 95.0% 100.0% 85.7% 84.5% -5.0%
Footnotes 100.0% 95.2% 100.0% 100.0% -4.8%
FAQ 94.2% 90.2% 100.0% 92.0% 90.6% -4.0%
Card 100.0% 96.6% 100.0% 91.4% 84.6% -6.8%
BreakoutBanner 97.7% 95.5% 100.0% 89.8% 89.6% -2.2%
Accordion 97.9% 100.0% 100.0% 94.1% 100.0% +5.9%
Bento 82.4% 80.5% 94.4% 74.8% -1.9%
AnchorNav 93.0% 94.4% 91.7% 78.1% 77.9% +1.4%
CTAForm 91.3% 90.5% 100.0% 100.0% -0.8%
SubNav 85.2% 86.0% 84.8% 78.9% 80.9% +2.0%
FormControl 93.0% 93.2% 100.0% 91.5% 83.1% -8.4%
SubdomainNavBar 71.8% 71.9% 79.4% 70.3% 70.1% -0.2%
Statistic 97.3% 100.0% 91.4% 89.2% -2.2%
Tooltip 67.5% 52.9% 58.7% 58.3% -0.4%

Copy link
Contributor

@danielguillan danielguillan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rezrah rezrah merged commit 55474b4 into main Nov 25, 2025
23 checks passed
@rezrah rezrah deleted the rezrah/react-19-compat branch November 25, 2025 12:54
@github-actions github-actions bot mentioned this pull request Nov 25, 2025
@primer primer bot mentioned this pull request Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants