Skip to content

feat: add support for react compiler #6211

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

joshblack
Copy link
Member

Add support for React Compiler by following the guide in: https://react.dev/learn/react-compiler. We use the approach where we are opting out files from being processed by React Compiler (as recommended by the guide). Files that we are not processing with React Compiler are captured in our migration-status workflow.

Changelog

New

  • Add support for React Compiler through babel

Changed

  • Update config for vite in Storybook and vitest to include React Compiler settings

Removed

Rollout strategy

  • Minor release

Copy link

changeset-bot bot commented Jun 16, 2025

🦋 Changeset detected

Latest commit: ac6d583

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

This PR includes changesets to release 1 package
Name Type
@primer/react 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 github-actions bot added staff Author is a staff member integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Jun 16, 2025
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

@github-actions github-actions bot requested a deployment to storybook-preview-6211 June 16, 2025 20:48 Abandoned
Copy link
Contributor

github-actions bot commented Jun 16, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 92.67 KB (0%)
packages/react/dist/browser.umd.js 92.54 KB (0%)

@github-actions github-actions bot requested a deployment to storybook-preview-6211 June 16, 2025 20:53 Abandoned
@joshblack joshblack marked this pull request as ready for review June 16, 2025 21:03
@Copilot Copilot AI review requested due to automatic review settings June 16, 2025 21:03
@joshblack joshblack requested a review from a team as a code owner June 16, 2025 21:03
Copy link
Contributor

@Copilot 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

Add support for React Compiler by integrating babel-plugin-react-compiler into our build and test pipelines and adding a migration-status reporting script.

  • Introduce script/react-compiler-migration-status.mts to track which files are migrated or not.
  • Update Vitest, Rollup, Babel, Storybook, and Vite configs to apply the React Compiler plugin selectively.
  • Add required dependencies and a GitHub Actions job to surface migration status.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
script/react-compiler-migration-status.mts New script to report migration progress
packages/react/vitest.config.mts Added React Compiler plugin to Vitest config
packages/react/script/react-compiler.mjs Define which files are supported by React Compiler
packages/react/rollup.config.mjs Enable React Compiler plugin in Rollup build
packages/react/package.json Add React Compiler runtime and plugin deps
packages/react/babel.config.js Enable React Compiler plugin in Babel config
packages/react/.storybook/main.ts Enable React Compiler plugin in Storybook
.github/workflows/migration-status.yml Added CI job for migration status
.changeset/clean-ends-end.md Documented minor release bump
Comments suppressed due to low confidence (1)

.github/workflows/migration-status.yml:15

  • [nitpick] Pinning to Node.js version 22 may not be available on GitHub Actions runners yet; consider using a current LTS like 20 or specifying a semver range.
node-version: 22

import fs from 'node:fs'
import {files, notMigrated as notMigratedFiles} from '../packages/react/script/react-compiler.mjs'

const directory = path.resolve(import.meta.dirname, '..')
Copy link
Preview

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

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

import.meta.dirname is not a standard ES module property; use fileURLToPath(import.meta.url) and path.dirname to compute the script directory.

Copilot uses AI. Check for mistakes.

@@ -1,10 +1,18 @@
const defines = require('./babel-defines')
const {isSupported} = require('./script/react-compiler.mjs')
Copy link
Preview

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

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

Requiring an ES module (.mjs) via CommonJS require will fail at runtime; convert this config to ESM or use dynamic import() or rename to a .cjs file.

Copilot uses AI. Check for mistakes.

Comment on lines +6 to +29
const migrated = files
.filter(filepath => {
return notMigratedFiles.indexOf(filepath) === -1
})
.map(filepath => {
const stats = fs.statSync(filepath)
return {
filepath,
size: stats.size,
}
})
const notMigrated = notMigratedFiles.map(filepath => {
const stats = fs.statSync(filepath)
return {
filepath,
size: stats.size,
}
})

let totalSize = 0

for (const filepath of files) {
const stats = fs.statSync(filepath)
totalSize += stats.size
Copy link
Preview

Copilot AI Jun 16, 2025

Choose a reason for hiding this comment

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

[nitpick] The script calls fs.statSync on each file multiple times (for total and migrated sizes); consolidate these into a single pass to reduce filesystem operations.

Suggested change
const migrated = files
.filter(filepath => {
return notMigratedFiles.indexOf(filepath) === -1
})
.map(filepath => {
const stats = fs.statSync(filepath)
return {
filepath,
size: stats.size,
}
})
const notMigrated = notMigratedFiles.map(filepath => {
const stats = fs.statSync(filepath)
return {
filepath,
size: stats.size,
}
})
let totalSize = 0
for (const filepath of files) {
const stats = fs.statSync(filepath)
totalSize += stats.size
const fileStatsMap = Object.fromEntries(
files.map(filepath => [filepath, fs.statSync(filepath)])
)
const migrated = files
.filter(filepath => {
return notMigratedFiles.indexOf(filepath) === -1
})
.map(filepath => ({
filepath,
size: fileStatsMap[filepath].size,
}))
const notMigrated = notMigratedFiles.map(filepath => ({
filepath,
size: fileStatsMap[filepath].size,
}))
let totalSize = 0
for (const filepath of files) {
totalSize += fileStatsMap[filepath].size

Copilot uses AI. Check for mistakes.

@primer-integration
Copy link

👋 Hi from github/github! Your integration PR is ready: https://github.com/github/github/pull/384580

@primer-integration
Copy link

🔴 golden-jobs completed with status failure.

@github-actions github-actions bot added integration-tests: failing Changes in this PR cause breaking changes in gh/gh and removed integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Jun 17, 2025
Copy link
Contributor

@hectahertz hectahertz left a comment

Choose a reason for hiding this comment

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

Love this approach, let's do it! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: failing Changes in this PR cause breaking changes in gh/gh staff Author is a staff member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants