-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically use createRoot for React@>=18 (#26279)
Also logs a message when defaulting, and a warning when using a prerelease build of `react-dom` (e.g. the React 18 alpha) which are not officially supported. Note: I've done this in `webpack-config.ts` instead of the Next.js config, as we don't actually want you to be able to opt-out *without* downgrading back to React 17, and so it ought to be entirely removed from the config eventually.
- Loading branch information
Showing
8 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!node_modules |
1 change: 1 addition & 0 deletions
1
test/integration/react-18/prerelease/node_modules/react-dom/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
test/integration/react-18/prerelease/node_modules/react-dom/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"react-dom": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Index() { | ||
return <p>Hello</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Index() { | ||
return <p>Hello</p> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* eslint-env jest */ | ||
|
||
import { findPort, killApp, launchApp, runNextCommand } from 'next-test-utils' | ||
import { join } from 'path' | ||
|
||
jest.setTimeout(1000 * 60 * 5) | ||
|
||
const dirSupported = join(__dirname, '../supported') | ||
const dirPrerelease = join(__dirname, '../prerelease') | ||
|
||
const UNSUPPORTED_PRERELEASE = | ||
"You are using an unsupported prerelease of 'react-dom'" | ||
const USING_CREATE_ROOT = 'Using the createRoot API for React' | ||
|
||
async function getBuildOutput(dir) { | ||
const { stdout, stderr } = await runNextCommand(['build', dir], { | ||
stdout: true, | ||
stderr: true, | ||
}) | ||
return stdout + stderr | ||
} | ||
|
||
async function getDevOutput(dir) { | ||
const port = await findPort() | ||
|
||
let stdout = '' | ||
let stderr = '' | ||
let instance = await launchApp(dir, port, { | ||
stdout: true, | ||
stderr: true, | ||
onStdout(msg) { | ||
stdout += msg | ||
}, | ||
onStderr(msg) { | ||
stderr += msg | ||
}, | ||
}) | ||
await killApp(instance) | ||
return stdout + stderr | ||
} | ||
|
||
describe('React 18 Support', () => { | ||
describe('build', () => { | ||
test('supported version of React', async () => { | ||
const output = await getBuildOutput(dirSupported) | ||
expect(output).not.toMatch(USING_CREATE_ROOT) | ||
expect(output).not.toMatch(UNSUPPORTED_PRERELEASE) | ||
}) | ||
|
||
test('prerelease version of React', async () => { | ||
const output = await getBuildOutput(dirPrerelease) | ||
expect(output).toMatch(USING_CREATE_ROOT) | ||
expect(output).toMatch(UNSUPPORTED_PRERELEASE) | ||
}) | ||
}) | ||
|
||
describe('dev', () => { | ||
test('supported version of React', async () => { | ||
let output = await getDevOutput(dirSupported) | ||
expect(output).not.toMatch(USING_CREATE_ROOT) | ||
expect(output).not.toMatch(UNSUPPORTED_PRERELEASE) | ||
}) | ||
|
||
test('prerelease version of React', async () => { | ||
let output = await getDevOutput(dirPrerelease) | ||
expect(output).toMatch(USING_CREATE_ROOT) | ||
expect(output).toMatch(UNSUPPORTED_PRERELEASE) | ||
}) | ||
}) | ||
}) |