Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
632725b0
Unverified
Commit
632725b0
authored
Feb 21, 2026
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Feb 21, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[sync-react] Allow syncing React with local build (#90277)
parent
cde39614
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
51 deletions
+119
-51
sync-react.js
scripts/sync-react.js
+119
-51
No files found.
scripts/sync-react.js
View file @
632725b0
...
@@ -3,13 +3,22 @@
...
@@ -3,13 +3,22 @@
const
path
=
require
(
'path'
)
const
path
=
require
(
'path'
)
const
fsp
=
require
(
'fs/promises'
)
const
fsp
=
require
(
'fs/promises'
)
const
process
=
require
(
'process'
)
const
process
=
require
(
'process'
)
const
{
pathToFileURL
}
=
require
(
'url'
)
const
execa
=
require
(
'execa'
)
const
execa
=
require
(
'execa'
)
const
{
Octokit
}
=
require
(
'octokit'
)
const
{
Octokit
}
=
require
(
'octokit'
)
const
SemVer
=
require
(
'semver'
)
const
SemVer
=
require
(
'semver'
)
const
yargs
=
require
(
'yargs'
)
const
yargs
=
require
(
'yargs'
)
/** @type {any} */
// Use this script to update Next's vendored copy of React and related packages:
const
fetch
=
require
(
'node-fetch'
)
//
// Basic usage (defaults to most recent React canary version):
// pnpm run sync-react
//
// Update package.json but skip installing the dependencies automatically:
// pnpm run sync-react --no-install
//
// Sync from a local checkout of React (requires having React built first):
// pnpm run sync-react --version /path/to/react/checkout/
const
repoOwner
=
'vercel'
const
repoOwner
=
'vercel'
const
repoName
=
'next.js'
const
repoName
=
'next.js'
...
@@ -45,6 +54,10 @@ const appManifestsInstallingNextjsPeerDependencies = [
...
@@ -45,6 +54,10 @@ const appManifestsInstallingNextjsPeerDependencies = [
]
]
async
function
getSchedulerVersion
(
reactVersion
)
{
async
function
getSchedulerVersion
(
reactVersion
)
{
if
(
reactVersion
.
startsWith
(
'file://'
))
{
return
reactVersion
}
const
url
=
`https://registry.npmjs.org/react-dom/
${
reactVersion
}
`
const
url
=
`https://registry.npmjs.org/react-dom/
${
reactVersion
}
`
const
response
=
await
fetch
(
url
,
{
const
response
=
await
fetch
(
url
,
{
headers
:
{
headers
:
{
...
@@ -62,13 +75,18 @@ async function getSchedulerVersion(reactVersion) {
...
@@ -62,13 +75,18 @@ async function getSchedulerVersion(reactVersion) {
return
manifest
.
dependencies
[
'scheduler'
]
return
manifest
.
dependencies
[
'scheduler'
]
}
}
// Use this script to update Next's vendored copy of React and related packages:
/**
//
* @param {string} packageName
// Basic usage (defaults to most recent React canary version):
* @param {string} versionStr An NPM version or a file URL to a React checkout
// pnpm run sync-react
* @returns {string}
//
*/
// Update package.json but skip installing the dependencies automatically:
function
getPackageVersion
(
packageName
,
versionStr
)
{
// pnpm run sync-react --no-install
if
(
versionStr
.
startsWith
(
'file://'
))
{
return
new
URL
(
packageName
,
versionStr
).
href
}
return
`npm:
${
packageName
}
@
${
versionStr
}
`
}
async
function
sync
({
channel
,
newVersionStr
,
noInstall
})
{
async
function
sync
({
channel
,
newVersionStr
,
noInstall
})
{
const
useExperimental
=
channel
===
'experimental'
const
useExperimental
=
channel
===
'experimental'
...
@@ -88,32 +106,45 @@ async function sync({ channel, newVersionStr, noInstall }) {
...
@@ -88,32 +106,45 @@ async function sync({ channel, newVersionStr, noInstall }) {
return
return
}
}
const
baseSchedulerVersionStr
=
devDependencies
[
useExperimental
?
'scheduler-experimental-builtin'
:
'scheduler-builtin'
].
replace
(
/^npm:scheduler@/
,
''
)
const
newSchedulerVersionStr
=
await
getSchedulerVersion
(
newVersionStr
)
const
newSchedulerVersionStr
=
await
getSchedulerVersion
(
newVersionStr
)
console
.
log
(
`Updating "scheduler@
${
channel
}
" to
${
newSchedulerVersionStr
}
...`
)
console
.
log
(
`Updating "scheduler@
${
channel
}
" to
${
newSchedulerVersionStr
}
...`
)
for
(
const
[
dep
,
version
]
of
Object
.
entries
(
devDependencies
))
{
for
(
const
packageName
of
[
'react'
,
'react-dom'
])
{
if
(
version
.
endsWith
(
baseVersionStr
))
{
devDependencies
[
devDependencies
[
dep
]
=
version
.
replace
(
baseVersionStr
,
newVersionStr
)
`
${
packageName
}${
useExperimental
?
'-experimental'
:
''
}
-builtin`
}
else
if
(
version
.
endsWith
(
baseSchedulerVersionStr
))
{
]
=
getPackageVersion
(
packageName
,
newVersionStr
)
devDependencies
[
dep
]
=
version
.
replace
(
baseSchedulerVersionStr
,
if
(
!
useExperimental
)
{
newSchedulerVersionStr
pnpmOverrides
[
packageName
]
=
getPackageVersion
(
packageName
,
newVersionStr
)
)
}
}
}
}
for
(
const
[
dep
,
version
]
of
Object
.
entries
(
pnpmOverrides
))
{
if
(
version
.
endsWith
(
baseVersionStr
))
{
for
(
const
packageName
of
[
pnpmOverrides
[
dep
]
=
version
.
replace
(
baseVersionStr
,
newVersionStr
)
'react-server-dom-turbopack'
,
}
else
if
(
version
.
endsWith
(
baseSchedulerVersionStr
))
{
'react-server-dom-webpack'
,
pnpmOverrides
[
dep
]
=
version
.
replace
(
])
{
baseSchedulerVersionStr
,
devDependencies
[
`
${
packageName
}${
useExperimental
?
'-experimental'
:
''
}
`
]
=
newSchedulerVersionStr
getPackageVersion
(
packageName
,
newVersionStr
)
)
}
}
}
devDependencies
[
`scheduler-
${
useExperimental
?
'experimental-'
:
''
}
builtin`
]
=
getPackageVersion
(
'scheduler'
,
newSchedulerVersionStr
)
if
(
!
useExperimental
)
{
pnpmOverrides
.
scheduler
=
getPackageVersion
(
'scheduler'
,
newSchedulerVersionStr
)
// TODO: Should be handled like the other React packages
devDependencies
[
'react-is-builtin'
]
=
newVersionStr
.
startsWith
(
'file://'
)
?
new
URL
(
'react-is'
,
newVersionStr
).
href
:
`npm:react-is@
${
newVersionStr
}
`
pnpmOverrides
[
'react-is'
]
=
newVersionStr
.
startsWith
(
'file://'
)
?
new
URL
(
'react-is'
,
newVersionStr
).
href
:
`npm:react-is@
${
newVersionStr
}
`
}
await
fsp
.
writeFile
(
await
fsp
.
writeFile
(
path
.
join
(
cwd
,
'package.json'
),
path
.
join
(
cwd
,
'package.json'
),
JSON
.
stringify
(
pkgJson
,
null
,
2
)
+
JSON
.
stringify
(
pkgJson
,
null
,
2
)
+
...
@@ -122,8 +153,25 @@ async function sync({ channel, newVersionStr, noInstall }) {
...
@@ -122,8 +153,25 @@ async function sync({ channel, newVersionStr, noInstall }) {
)
)
}
}
function
extractInfoFromReactVersion
(
reactVersion
)
{
/**
const
match
=
reactVersion
.
match
(
* @typedef {object} ReactVersionInfo
* @property {string} semverVersion - The semver version of React.
* @property {string} releaseLabel - The release label of React (e.g. "canary", "rc").
* @property {string} sha - The commit SHA of the React version.
* @property {string} dateString - The date string of the React version.
* @returns {ReactVersionInfo}
*/
function
extractInfoFromReactVersion
(
versionStr
)
{
if
(
versionStr
.
startsWith
(
'file://'
))
{
return
{
dateString
:
new
Date
().
toISOString
().
split
(
'T'
)[
0
],
releaseLabel
:
'local'
,
semverVersion
:
'0.0.0'
,
sha
:
'local'
,
}
}
const
match
=
versionStr
.
match
(
/
(?<
semverVersion>.*
)
-
(?<
releaseLabel>.*
)
-
(?<
sha>.*
)
-
(?<
dateString>.*
)
$/
/
(?<
semverVersion>.*
)
-
(?<
releaseLabel>.*
)
-
(?<
sha>.*
)
-
(?<
dateString>.*
)
$/
)
)
return
match
?
match
.
groups
:
null
return
match
?
match
.
groups
:
null
...
@@ -134,10 +182,10 @@ async function getChangelogFromGitHub(baseSha, newSha) {
...
@@ -134,10 +182,10 @@ async function getChangelogFromGitHub(baseSha, newSha) {
let
changelog
=
[]
let
changelog
=
[]
for
(
let
currentPage
=
1
;
;
currentPage
++
)
{
for
(
let
currentPage
=
1
;
;
currentPage
++
)
{
const
url
=
`https://api.github.com/repos/facebook/react/compare/
${
baseSha
}
...
${
newSha
}
?per_page=
${
pageSize
}
&page=
${
currentPage
}
`
const
url
=
`https://api.github.com/repos/facebook/react/compare/
${
baseSha
}
...
${
newSha
}
?per_page=
${
pageSize
}
&page=
${
currentPage
}
`
const
headers
=
{}
const
headers
=
new
Headers
()
// GITHUB_TOKEN is optional but helps in case of rate limiting during development.
// GITHUB_TOKEN is optional but helps in case of rate limiting during development.
if
(
process
.
env
.
GITHUB_TOKEN
)
{
if
(
process
.
env
.
GITHUB_TOKEN
)
{
headers
.
Authorization
=
`token
${
process
.
env
.
GITHUB_TOKEN
}
`
headers
.
set
(
'Authorization'
,
`token
${
process
.
env
.
GITHUB_TOKEN
}
`
)
}
}
const
response
=
await
fetch
(
url
,
{
const
response
=
await
fetch
(
url
,
{
headers
,
headers
,
...
@@ -229,7 +277,14 @@ async function main() {
...
@@ -229,7 +277,14 @@ async function main() {
})
})
.
options
(
'install'
,
{
default
:
true
,
type
:
'boolean'
})
.
options
(
'install'
,
{
default
:
true
,
type
:
'boolean'
})
.
options
(
'version'
,
{
default
:
null
,
type
:
'string'
}).
argv
.
options
(
'version'
,
{
default
:
null
,
type
:
'string'
}).
argv
const
{
actor
,
createPull
,
commit
,
install
,
version
}
=
argv
let
{
actor
,
createPull
,
commit
,
install
,
version
}
=
argv
if
(
version
!==
null
&&
version
.
startsWith
(
'/'
))
{
version
=
pathToFileURL
(
version
).
href
// Ensure trailing slash so that the URL is treated as a directory.
if
(
!
version
.
endsWith
(
'/'
))
{
version
+=
'/'
}
}
async
function
commitEverything
(
message
)
{
async
function
commitEverything
(
message
)
{
await
execa
(
'git'
,
[
'add'
,
'-A'
])
await
execa
(
'git'
,
[
'add'
,
'-A'
])
...
@@ -281,7 +336,10 @@ Or, run this command with no arguments to use the most recently published versio
...
@@ -281,7 +336,10 @@ Or, run this command with no arguments to use the most recently published versio
}
}
const
{
sha
:
newSha
,
dateString
:
newDateString
}
=
newVersionInfo
const
{
sha
:
newSha
,
dateString
:
newDateString
}
=
newVersionInfo
const
branchName
=
`update/react/
${
newVersionStr
}
`
const
branchName
=
newVersionStr
.
startsWith
(
'file://'
)
?
// left to user to name their local sync branch
`update/react/local`
:
`update/react/
${
newVersionStr
}
`
if
(
createPull
)
{
if
(
createPull
)
{
const
{
exitCode
,
all
,
command
}
=
await
execa
(
const
{
exitCode
,
all
,
command
}
=
await
execa
(
'git'
,
'git'
,
...
@@ -319,8 +377,14 @@ Or, run this command with no arguments to use the most recently published versio
...
@@ -319,8 +377,14 @@ Or, run this command with no arguments to use the most recently published versio
''
''
)
)
let
experimentalNewVersionStr
=
`0.0.0-experimental-
${
newSha
}
-
${
newDateString
}
`
if
(
version
!==
null
&&
version
.
startsWith
(
'file://'
))
{
experimentalNewVersionStr
=
new
URL
(
'build/oss-experimental/'
,
version
).
href
newVersionStr
=
new
URL
(
'build/oss-stable/'
,
version
).
href
}
await
sync
({
await
sync
({
newVersionStr
:
`0.0.0-experimental-
${
newSha
}
-
${
newDateString
}
`
,
newVersionStr
:
experimentalNewVersionStr
,
noInstall
:
!
install
,
noInstall
:
!
install
,
channel
:
'experimental'
,
channel
:
'experimental'
,
})
})
...
@@ -470,23 +534,27 @@ Or, run this command with no arguments to use the most recently published versio
...
@@ -470,23 +534,27 @@ Or, run this command with no arguments to use the most recently published versio
}
}
let
prDescription
=
''
let
prDescription
=
''
if
(
syncPagesRouterReact
)
{
if
(
newVersionInfo
.
releaseLabel
===
'local'
)
{
prDescription
+=
`**breaking change for canary users: Bumps peer dependency of React from \`
${
baseVersionStr
}
\` to \`
${
pagesRouterReactVersion
}
\`**\n\n`
prDescription
=
"Can't generate a changelog for local builds"
}
}
else
{
if
(
syncPagesRouterReact
)
{
prDescription
+=
`**breaking change for canary users: Bumps peer dependency of React from \`
${
baseVersionStr
}
\` to \`
${
pagesRouterReactVersion
}
\`**\n\n`
}
// Fetch the changelog from GitHub and print it to the console.
// Fetch the changelog from GitHub and print it to the console.
prDescription
+=
`[diff facebook/react@
${
baseSha
}
...
${
newSha
}
](https://github.com/facebook/react/compare/
${
baseSha
}
...
${
newSha
}
)\n\n`
prDescription
+=
`[diff facebook/react@
${
baseSha
}
...
${
newSha
}
](https://github.com/facebook/react/compare/
${
baseSha
}
...
${
newSha
}
)\n\n`
try
{
try
{
const
changelog
=
await
getChangelogFromGitHub
(
baseSha
,
newSha
)
const
changelog
=
await
getChangelogFromGitHub
(
baseSha
,
newSha
)
if
(
changelog
===
null
)
{
if
(
changelog
===
null
)
{
prDescription
+=
`GitHub reported no changes between
${
baseSha
}
and
${
newSha
}
.`
prDescription
+=
`GitHub reported no changes between
${
baseSha
}
and
${
newSha
}
.`
}
else
{
}
else
{
prDescription
+=
`<details>\n<summary>React upstream changes</summary>\n\n
${
changelog
}
\n\n</details>`
prDescription
+=
`<details>\n<summary>React upstream changes</summary>\n\n
${
changelog
}
\n\n</details>`
}
}
catch
(
error
)
{
console
.
error
(
error
)
prDescription
+=
'
\
nFailed to fetch changelog from GitHub. Changes were applied, anyway.
\
n'
}
}
}
catch
(
error
)
{
console
.
error
(
error
)
prDescription
+=
'
\
nFailed to fetch changelog from GitHub. Changes were applied, anyway.
\
n'
}
}
if
(
!
install
)
{
if
(
!
install
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment