Unverified Commit 1ee500b0 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Use React 19.1 everywhere (#77895)

parent 920b48dc
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
}, },
"dependencies": { "dependencies": {
"next": "canary", "next": "canary",
"react": "^19.0.0", "react": "19.1.0",
"react-dom": "^19.0.0" "react-dom": "19.1.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22", "@types/node": "^22",
......
...@@ -13,7 +13,7 @@ import { GetTemplateFileArgs, InstallTemplateArgs } from "./types"; ...@@ -13,7 +13,7 @@ import { GetTemplateFileArgs, InstallTemplateArgs } from "./types";
// Do not rename or format. sync-react script relies on this line. // Do not rename or format. sync-react script relies on this line.
// prettier-ignore // prettier-ignore
const nextjsReactPeerVersion = "^19.0.0"; const nextjsReactPeerVersion = "19.1.0";
/** /**
* Get the file path for a given file in a template, e.g. "next.config.js". * Get the file path for a given file in a template, e.g. "next.config.js".
......
...@@ -19,7 +19,7 @@ const { getTestFilter } = require('./test/get-test-filter') ...@@ -19,7 +19,7 @@ const { getTestFilter } = require('./test/get-test-filter')
// Do not rename or format. sync-react script relies on this line. // Do not rename or format. sync-react script relies on this line.
// prettier-ignore // prettier-ignore
const nextjsReactPeerVersion = "^19.0.0"; const nextjsReactPeerVersion = "19.1.0";
let argv = require('yargs/yargs')(process.argv.slice(2)) let argv = require('yargs/yargs')(process.argv.slice(2))
.string('type') .string('type')
......
...@@ -5,6 +5,7 @@ const fsp = require('fs/promises') ...@@ -5,6 +5,7 @@ const fsp = require('fs/promises')
const process = require('process') const process = require('process')
const execa = require('execa') const execa = require('execa')
const { Octokit } = require('octokit') const { Octokit } = require('octokit')
const SemVer = require('semver')
const yargs = require('yargs') const yargs = require('yargs')
/** @type {any} */ /** @type {any} */
...@@ -17,9 +18,13 @@ const pullRequestReviewers = ['eps1lon'] ...@@ -17,9 +18,13 @@ const pullRequestReviewers = ['eps1lon']
/** /**
* Set to `null` to automatically sync the React version of Pages Router with App Router React version. * Set to `null` to automatically sync the React version of Pages Router with App Router React version.
* Set to a specific version to override the Pages Router React version e.g. `^19.0.0`. * Set to a specific version to override the Pages Router React version e.g. `^19.0.0`.
*
* "Active" just refers to our current development practice. While we do support
* React 18 in pages router, we don't focus our development process on it considering
* it does not receive new features.
* @type {string | null} * @type {string | null}
*/ */
const pagesRouterReact = '^19.0.0' const activePagesRouterReact = '^19.0.0'
const defaultLatestChannel = 'canary' const defaultLatestChannel = 'canary'
const filesReferencingReactPeerDependencyVersion = [ const filesReferencingReactPeerDependencyVersion = [
...@@ -176,6 +181,31 @@ async function getChangelogFromGitHub(baseSha, newSha) { ...@@ -176,6 +181,31 @@ async function getChangelogFromGitHub(baseSha, newSha) {
return changelog.length > 0 ? changelog.join('\n') : null return changelog.length > 0 ? changelog.join('\n') : null
} }
async function findHighestNPMReactVersion(versionLike) {
const { stdout, stderr } = await execa(
'npm',
['--silent', 'view', '--json', `react@${versionLike}`, 'version'],
{
// Avoid "Usage Error: This project is configured to use pnpm".
cwd: '/tmp',
}
)
if (stderr) {
console.error(stderr)
throw new Error(
`Failed to read highest react@${versionLike} version from npm.`
)
}
const result = JSON.parse(stdout)
return typeof result === 'string'
? result
: result.sort((a, b) => {
return SemVer.compare(b, a)
})[0]
}
async function main() { async function main() {
const cwd = process.cwd() const cwd = process.cwd()
const errors = [] const errors = []
...@@ -232,19 +262,7 @@ async function main() { ...@@ -232,19 +262,7 @@ async function main() {
// TODO: Fork arguments in GitHub workflow to ensure `--version ""` is considered a mistake // TODO: Fork arguments in GitHub workflow to ensure `--version ""` is considered a mistake
newVersionStr === '' newVersionStr === ''
) { ) {
const { stdout, stderr } = await execa( newVersionStr = await findHighestNPMReactVersion(defaultLatestChannel)
'npm',
['--silent', 'view', `react@${defaultLatestChannel}`, 'version'],
{
// Avoid "Usage Error: This project is configured to use pnpm".
cwd: '/tmp',
}
)
if (stderr) {
console.error(stderr)
throw new Error('Failed to read latest React canary version from npm.')
}
newVersionStr = stdout.trim()
console.log( console.log(
`--version was not provided. Using react@${defaultLatestChannel}: ${newVersionStr}` `--version was not provided. Using react@${defaultLatestChannel}: ${newVersionStr}`
) )
...@@ -325,10 +343,14 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -325,10 +343,14 @@ Or, run this command with no arguments to use the most recently published versio
) )
} }
const syncPagesRouterReact = pagesRouterReact === null const syncPagesRouterReact = activePagesRouterReact === null
const pagesRouterReactVersion = syncPagesRouterReact const newActivePagesRouterReactVersion = syncPagesRouterReact
? newVersionStr ? newVersionStr
: pagesRouterReact : activePagesRouterReact
const pagesRouterReactVersion = `^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ${newActivePagesRouterReactVersion}`
const highestPagesRouterReactVersion = await findHighestNPMReactVersion(
pagesRouterReactVersion
)
const { sha: baseSha, dateString: baseDateString } = baseVersionInfo const { sha: baseSha, dateString: baseDateString } = baseVersionInfo
if (syncPagesRouterReact) { if (syncPagesRouterReact) {
...@@ -336,13 +358,13 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -336,13 +358,13 @@ Or, run this command with no arguments to use the most recently published versio
const filePath = path.join(cwd, fileName) const filePath = path.join(cwd, fileName)
const previousSource = await fsp.readFile(filePath, 'utf-8') const previousSource = await fsp.readFile(filePath, 'utf-8')
const updatedSource = previousSource.replace( const updatedSource = previousSource.replace(
`const nextjsReactPeerVersion = "${baseVersionStr}";`, /const nextjsReactPeerVersion = "[^"]+";/,
`const nextjsReactPeerVersion = "${pagesRouterReactVersion}";` `const nextjsReactPeerVersion = "${highestPagesRouterReactVersion}";`
) )
if (pagesRouterReact === null && updatedSource === previousSource) { if (activePagesRouterReact === null && updatedSource === previousSource) {
errors.push( errors.push(
new Error( new Error(
`${fileName}: Failed to update ${baseVersionStr} to ${pagesRouterReactVersion}. Is this file still referencing the React peer dependency version?` `${fileName}: Failed to update ${baseVersionStr} to ${highestPagesRouterReactVersion}. Is this file still referencing the React peer dependency version?`
) )
) )
} else { } else {
...@@ -356,10 +378,10 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -356,10 +378,10 @@ Or, run this command with no arguments to use the most recently published versio
const packageJson = await fsp.readFile(packageJsonPath, 'utf-8') const packageJson = await fsp.readFile(packageJsonPath, 'utf-8')
const manifest = JSON.parse(packageJson) const manifest = JSON.parse(packageJson)
if (manifest.dependencies['react']) { if (manifest.dependencies['react']) {
manifest.dependencies['react'] = pagesRouterReactVersion manifest.dependencies['react'] = highestPagesRouterReactVersion
} }
if (manifest.dependencies['react-dom']) { if (manifest.dependencies['react-dom']) {
manifest.dependencies['react-dom'] = pagesRouterReactVersion manifest.dependencies['react-dom'] = highestPagesRouterReactVersion
} }
await fsp.writeFile( await fsp.writeFile(
packageJsonPath, packageJsonPath,
...@@ -379,12 +401,10 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -379,12 +401,10 @@ Or, run this command with no arguments to use the most recently published versio
const manifest = JSON.parse(packageJson) const manifest = JSON.parse(packageJson)
// Need to specify last supported RC version to avoid breaking changes. // Need to specify last supported RC version to avoid breaking changes.
if (manifest.peerDependencies['react']) { if (manifest.peerDependencies['react']) {
manifest.peerDependencies['react'] = manifest.peerDependencies['react'] = pagesRouterReactVersion
`^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ${pagesRouterReactVersion}`
} }
if (manifest.peerDependencies['react-dom']) { if (manifest.peerDependencies['react-dom']) {
manifest.peerDependencies['react-dom'] = manifest.peerDependencies['react-dom'] = pagesRouterReactVersion
`^18.2.0 || 19.0.0-rc-de68d2f4-20241204 || ${pagesRouterReactVersion}`
} }
await fsp.writeFile( await fsp.writeFile(
packageJsonPath, packageJsonPath,
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"next": "latest", "next": "latest",
"react": "^19.0.0", "react": "19.1.0",
"react-dom": "^19.0.0" "react-dom": "19.1.0"
}, },
"engines": { "engines": {
"node": ">=18.18.0" "node": ">=18.18.0"
......
...@@ -11,11 +11,6 @@ describe('Error overlay for hydration errors in Pages router', () => { ...@@ -11,11 +11,6 @@ describe('Error overlay for hydration errors in Pages router', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')), files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true, skipStart: true,
// TODO: once Next.js minimal React version is 19.1, remove this override.
dependencies: {
react: isReact18 ? '^18.3.1' : '^19.1.0',
'react-dom': isReact18 ? '^18.3.1' : '^19.1.0',
},
}) })
it('includes a React docs link when hydration error does occur', async () => { it('includes a React docs link when hydration error does occur', async () => {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
}, },
"dependencies": { "dependencies": {
"next": "canary", "next": "canary",
"react": "^19.0.0", "react": "19.1.0",
"react-dom": "^19.0.0" "react-dom": "19.1.0"
} }
} }
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
}, },
"dependencies": { "dependencies": {
"next": "canary", "next": "canary",
"react": "^19.0.0", "react": "19.1.0",
"react-dom": "^19.0.0" "react-dom": "19.1.0"
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^18", "@types/react": "^18",
......
...@@ -58,7 +58,7 @@ type OmitFirstArgument<F> = F extends ( ...@@ -58,7 +58,7 @@ type OmitFirstArgument<F> = F extends (
// Do not rename or format. sync-react script relies on this line. // Do not rename or format. sync-react script relies on this line.
// prettier-ignore // prettier-ignore
const nextjsReactPeerVersion = "^19.0.0"; const nextjsReactPeerVersion = "19.1.0";
export class NextInstance { export class NextInstance {
protected files: ResolvedFileConfig protected files: ResolvedFileConfig
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment