Unverified Commit 4a7ab34b authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update repo to use react 18 by default (#35888)

This updates our `yarn next` command to leverage react v18 by default and removes the need for the test require hook/config modifying when testing react 18. There are some fixtures we need to investigate react 18 support in follow-ups:

- `test/integration/client-navigation-a11y`
- `test/integration/critical-css`
- `test/integration/custom-error-page-exception`
- `test/integration/font-optimization`
- AMP specific tests
parent 67d25a58
......@@ -36,7 +36,7 @@
"lint-staged": "lint-staged",
"next-with-deps": "./scripts/next-with-deps.sh",
"next": "node --trace-deprecation --enable-source-maps packages/next/dist/bin/next",
"next-react-18": "node --trace-deprecation --enable-source-maps -r ./test/integration/react-18/test/require-hook.js packages/next/dist/bin/next",
"next-react-17": "node --trace-deprecation --enable-source-maps -r ./test/lib/react-17-require-hook.js packages/next/dist/bin/next",
"next-no-sourcemaps": "node --trace-deprecation packages/next/dist/bin/next",
"clean-trace-jaeger": "rm -rf test/integration/basic/.next && TRACE_TARGET=JAEGER node --trace-deprecation --enable-source-maps packages/next/dist/bin/next build test/integration/basic",
"debug": "node --inspect packages/next/dist/bin/next",
......@@ -53,7 +53,7 @@
"@svgr/webpack": "5.5.0",
"@swc/cli": "0.1.55",
"@swc/core": "1.2.148",
"@testing-library/react": "11.2.5",
"@testing-library/react": "13.0.0",
"@types/cheerio": "0.22.16",
"@types/fs-extra": "8.1.0",
"@types/html-validator": "5.0.2",
......@@ -145,10 +145,10 @@
"pretty-bytes": "5.3.0",
"pretty-ms": "7.0.0",
"random-seed": "0.3.0",
"react": "17.0.2",
"react-18": "npm:react@18.0.0",
"react-dom": "17.0.2",
"react-dom-18": "npm:react-dom@18.0.0",
"react": "18.0.0",
"react-17": "npm:react@17.0.2",
"react-dom": "18.0.0",
"react-dom-17": "npm:react-dom@17.0.2",
"react-ssr-prepass": "1.0.8",
"react-virtualized": "9.22.3",
"relay-compiler": "13.0.2",
......
......@@ -128,7 +128,8 @@ const cachedPageRuntimeConfig = new Map<string, [number, PageRuntime]>()
// could be thousands of pages existing.
export async function getPageRuntime(
pageFilePath: string,
nextConfig: Partial<NextConfig>
nextConfig: Partial<NextConfig>,
isDev?: boolean
): Promise<PageRuntime> {
if (!nextConfig.experimental?.reactRoot) return undefined
......@@ -144,7 +145,7 @@ export async function getPageRuntime(
encoding: 'utf8',
})
} catch (err) {
if (process.env.NODE_ENV === 'production') throw err
if (!isDev) throw err
return undefined
}
......@@ -235,7 +236,8 @@ export async function createEntrypoints(
previewMode: __ApiPreviewProps,
config: NextConfigComplete,
loadedEnvFiles: LoadedEnvFiles,
pagesDir: string
pagesDir: string,
isDev?: boolean
): Promise<Entrypoints> {
const client: webpack5.EntryObject = {}
const server: webpack5.EntryObject = {}
......@@ -291,7 +293,7 @@ export async function createEntrypoints(
const pageFilePath = isInternalPages
? require.resolve(absolutePagePath)
: join(pagesDir, absolutePagePath.replace(PAGES_DIR_ALIAS, ''))
const pageRuntime = await getPageRuntime(pageFilePath, config)
const pageRuntime = await getPageRuntime(pageFilePath, config, isDev)
const isEdgeRuntime = pageRuntime === 'edge'
if (page.match(MIDDLEWARE_ROUTE)) {
......
......@@ -317,7 +317,8 @@ export default async function build(
previewProps,
config,
loadedEnvFiles,
pagesDir
pagesDir,
false
)
)
const pageKeys = Object.keys(mappedPages)
......
......@@ -339,7 +339,8 @@ export default class HotReloader {
this.previewProps,
this.config,
[],
this.pagesDir
this.pagesDir,
true
)
)
......@@ -418,7 +419,8 @@ export default class HotReloader {
this.previewProps,
this.config,
[],
this.pagesDir
this.pagesDir,
true
)
).client,
hasReactRoot: this.hasReactRoot,
......
const path = require('path')
let withReact18 = (config) => config
try {
// only used when running inside of the monorepo not when isolated
withReact18 = require(path.join(
__dirname,
'../../../integration/react-18/test/with-react-18'
))
} catch (_) {}
module.exports = withReact18({
module.exports = {
compiler: {
styledComponents: true,
},
})
}
module.exports = {
const path = require('path')
module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({
experimental: {
amp: {
optimizer: {
......@@ -9,4 +10,4 @@ module.exports = {
skipValidation: true,
},
},
}
})
......@@ -12,14 +12,19 @@ import {
let app
let appPort
const appDir = join(__dirname, '../')
const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')]
describe('AMP Custom Optimizer', () => {
it('should build and start for static page', async () => {
const { code } = await nextBuild(appDir, undefined)
const { code } = await nextBuild(appDir, undefined, {
nodeArgs,
})
expect(code).toBe(0)
appPort = await findPort()
app = await nextStart(appDir, appPort)
app = await nextStart(appDir, appPort, {
nodeArgs,
})
const html = await renderViaHTTP(appPort, '/')
await killApp(app)
......@@ -34,11 +39,11 @@ describe('AMP Custom Optimizer', () => {
})
it('should build and start for dynamic page', async () => {
const { code } = await nextBuild(appDir, undefined)
const { code } = await nextBuild(appDir, undefined, { nodeArgs })
expect(code).toBe(0)
appPort = await findPort()
app = await nextStart(appDir, appPort)
app = await nextStart(appDir, appPort, { nodeArgs })
const html = await renderViaHTTP(appPort, '/dynamic')
await killApp(app)
......
const path = require('path')
module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({})
......@@ -4,31 +4,29 @@ import { join } from 'path'
import cheerio from 'cheerio'
import { validateAMP } from 'amp-test-utils'
import {
stopApp,
startApp,
nextBuild,
nextServer,
renderViaHTTP,
nextStart,
findPort,
killApp,
} from 'next-test-utils'
const appDir = join(__dirname, '../')
const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')]
let appPort
let server
let app
describe('AMP Fragment Styles', () => {
beforeAll(async () => {
await nextBuild(appDir)
app = nextServer({
dir: join(__dirname, '../'),
dev: false,
quiet: true,
await nextBuild(appDir, [], {
nodeArgs,
})
appPort = await findPort()
app = await nextStart(appDir, appPort, {
nodeArgs,
})
server = await startApp(app)
appPort = server.address().port
})
afterAll(() => stopApp(server))
afterAll(() => killApp(app))
it('adds styles from fragment in AMP mode correctly', async () => {
const html = await renderViaHTTP(appPort, '/', { amp: 1 })
......
module.exports = {
const path = require('path')
module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({
onDemandEntries: {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60,
......@@ -7,4 +8,4 @@ module.exports = {
canonicalBase: 'http://localhost:1234',
},
// edit here
}
})
......@@ -10,18 +10,16 @@ import {
killApp,
launchApp,
nextBuild,
nextServer,
nextStart,
renderViaHTTP,
startApp,
stopApp,
waitFor,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'
const appDir = join(__dirname, '../')
const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')]
let appPort
let server
let app
const context = {}
......@@ -38,24 +36,21 @@ describe('AMP Usage', () => {
const result = await nextBuild(appDir, undefined, {
stdout: true,
stderr: true,
nodeArgs,
})
output = result.stdout + result.stderr
app = nextServer({
dir: join(__dirname, '../'),
dev: false,
quiet: true,
appPort = context.appPort = await findPort()
app = await nextStart(appDir, context.appPort, {
nodeArgs,
})
server = await startApp(app)
context.appPort = appPort = server.address().port
})
afterAll(async () => {
await rename(
join(appDir, 'pages/invalid-amp.js.bak'),
join(appDir, 'pages/invalid-amp.js')
)
return stopApp(server)
return killApp(app)
})
it('should have amp optimizer in trace', async () => {
......@@ -281,6 +276,7 @@ describe('AMP Usage', () => {
onStderr(msg) {
inspectPayload += msg
},
nodeArgs,
})
await renderViaHTTP(dynamicAppPort, '/only-amp')
......@@ -305,6 +301,7 @@ describe('AMP Usage', () => {
onStderr(msg) {
output += msg
},
nodeArgs,
})
})
......@@ -552,6 +549,7 @@ describe('AMP Usage', () => {
onStderr(msg) {
inspectPayload += msg
},
nodeArgs,
})
await renderViaHTTP(dynamicAppPort, '/invalid-amp')
......
module.exports = {
const path = require('path')
module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({
crossOrigin: 'anonymous',
}
})
......@@ -28,6 +28,10 @@ describe('Document and App', () => {
context.server = await launchApp(join(__dirname, '../'), context.appPort, {
onStdout: collectOutput,
onStderr: collectOutput,
nodeArgs: [
'-r',
join(__dirname, '../../../lib/react-17-require-hook.js'),
],
})
// pre-build all pages at the start
......
const path = require('path')
let handledServer = false
module.exports = {
webpack(cfg, { isServer }) {
......@@ -7,7 +8,8 @@ module.exports = {
cfg.entry = async () => {
const origEntries = await origEntry()
if (isServer) {
if (isServer && !handledServer) {
handledServer = true
const curEntry = origEntries['pages/_app']
origEntries['pages/_app'] = [
path.join(__dirname, 'lib/get-data.js'),
......
module.exports = {}
const path = require('path')
module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({})
......@@ -11,6 +11,7 @@ import { join } from 'path'
const context = {}
const appDir = join(__dirname, '../')
const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')]
const navigateTo = async (browser, selector) =>
await browser
......@@ -31,6 +32,7 @@ describe('Client Navigation accessibility', () => {
context.appPort = await findPort()
context.server = await launchApp(appDir, context.appPort, {
env: { __NEXT_TEST_WITH_DEVTOOL: 1 },
nodeArgs,
})
const prerender = [
......
module.exports = { experimental: { optimizeCss: true } }
......@@ -14,6 +14,7 @@ import fs from 'fs-extra'
const glob = promisify(globOrigig)
const appDir = join(__dirname, '../')
const nextConfig = join(appDir, 'next.config.js')
const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')]
let appPort
let app
......@@ -67,9 +68,13 @@ describe('CSS optimization for SSR apps', () => {
if (fs.pathExistsSync(join(appDir, '.next'))) {
await fs.remove(join(appDir, '.next'))
}
await nextBuild(appDir)
await nextBuild(appDir, undefined, {
nodeArgs,
})
appPort = await findPort()
app = await nextStart(appDir, appPort)
app = await nextStart(appDir, appPort, {
nodeArgs,
})
})
afterAll(async () => {
await killApp(app)
......@@ -85,9 +90,13 @@ describe('Font optimization for emulated serverless apps', () => {
`module.exports = { target: 'experimental-serverless-trace', experimental: {optimizeCss: true} }`,
'utf8'
)
await nextBuild(appDir)
await nextBuild(appDir, undefined, {
nodeArgs,
})
appPort = await findPort()
app = await nextStart(appDir, appPort)
app = await nextStart(appDir, appPort, {
nodeArgs,
})
})
afterAll(async () => {
await killApp(app)
......
const path = require('path')
module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({})
......@@ -5,14 +5,19 @@ import webdriver from 'next-webdriver'
import { nextBuild, nextStart, findPort, killApp, check } from 'next-test-utils'
const appDir = join(__dirname, '..')
const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')]
let appPort
let app
describe('Custom error page exception', () => {
beforeAll(async () => {
await nextBuild(appDir)
await nextBuild(appDir, undefined, {
nodeArgs,
})
appPort = await findPort()
app = await nextStart(appDir, appPort)
app = await nextStart(appDir, appPort, {
nodeArgs,
})
})
afterAll(() => killApp(app))
it('should handle errors from _error render', async () => {
......
......@@ -177,7 +177,7 @@ const runTests = (isDev = false) => {
const browser = await webdriver(appPort, '/rewriting-to-auto-export')
await check(
() => browser.eval(() => document.documentElement.innerHTML),
/auto-export hello/
/auto-export.*?hello/
)
expect(JSON.parse(await browser.elementByCss('#query').text())).toEqual({
rewrite: '1',
......@@ -2181,7 +2181,7 @@ describe('Custom routes', () => {
const browser = await webdriver(appPort, '/auto-export/my-slug')
await check(
() => browser.eval(() => document.documentElement.innerHTML),
/auto-export my-slug/
/auto-export.*?my-slug/
)
})
})
......
......@@ -98,7 +98,10 @@ describe('Custom Server', () => {
})
describe('with generateEtags enabled', () => {
beforeAll(() => startServer({ GENERATE_ETAGS: 'true' }))
beforeAll(async () => {
await nextBuild(appDir)
await startServer({ GENERATE_ETAGS: 'true', NODE_ENV: 'production' })
})
afterAll(() => killApp(server))
it('response includes etag header', async () => {
......
module.exports = {
const path = require('path')
module.exports = require(path.join(
__dirname,
'../../../../lib/with-react-17.js'
))({
cleanDistDir: false,
}
})
module.exports = {
const path = require('path')
module.exports = require(path.join(
__dirname,
'../../../../lib/with-react-17.js'
))({
cleanDistDir: false,
}
})
......@@ -15,6 +15,10 @@ import {
import webdriver from 'next-webdriver'
const fixturesDir = join(__dirname, '..', 'fixtures')
const nodeArgs = [
'-r',
join(__dirname, '../../../lib/react-17-require-hook.js'),
]
const fsExists = (file) =>
fs
......@@ -26,14 +30,14 @@ async function getBuildId(appDir) {
return fs.readFile(join(appDir, '.next', 'BUILD_ID'), 'utf8')
}
const startServerlessEmulator = async (dir, port) => {
const startServerlessEmulator = async (dir, port, opts = {}) => {
const scriptPath = join(dir, 'server.js')
const env = Object.assign(
{},
{ ...process.env },
{ PORT: port, BUILD_ID: await getBuildId(dir) }
)
return initNextServerScript(scriptPath, /ready on/i, env, false, {})
return initNextServerScript(scriptPath, /ready on/i, env, false, opts)
}
describe('Font Optimization', () => {
......@@ -218,7 +222,9 @@ describe('Font Optimization', () => {
// Re-run build to check if it works when build is cached
it('should work when build is cached', async () => {
await nextBuild(appDir)
await nextBuild(appDir, undefined, {
nodeArgs,
})
const testJson = JSON.parse(
await fs.readFile(builtPage('font-manifest.json'), {
encoding: 'utf-8',
......@@ -230,18 +236,16 @@ describe('Font Optimization', () => {
describe('Font optimization for SSR apps', () => {
beforeAll(async () => {
await fs.writeFile(
nextConfig,
`module.exports = { cleanDistDir: false }`,
'utf8'
)
if (fs.pathExistsSync(join(appDir, '.next'))) {
await fs.remove(join(appDir, '.next'))
}
await nextBuild(appDir)
await nextBuild(appDir, undefined, {
nodeArgs,
})
appPort = await findPort()
app = await nextStart(appDir, appPort)
app = await nextStart(appDir, appPort, {
nodeArgs,
})
builtServerPagesDir = join(appDir, '.next', 'server')
builtPage = (file) => join(builtServerPagesDir, file)
})
......@@ -250,37 +254,58 @@ describe('Font Optimization', () => {
})
describe('Font optimization for serverless apps', () => {
const origNextConfig = fs.readFileSync(nextConfig)
beforeAll(async () => {
await fs.writeFile(
nextConfig,
`module.exports = { target: 'serverless', cleanDistDir: false }`,
`
const path = require('path')
module.exports = require(path.join(__dirname, '../../../../lib/with-react-17.js'))({ target: 'serverless', cleanDistDir: false })
`,
'utf8'
)
await nextBuild(appDir)
await nextBuild(appDir, undefined, {
nodeArgs,
})
appPort = await findPort()
app = await nextStart(appDir, appPort)
app = await nextStart(appDir, appPort, {
nodeArgs,
})
builtServerPagesDir = join(appDir, '.next', 'serverless')
builtPage = (file) => join(builtServerPagesDir, file)
})
afterAll(() => killApp(app))
afterAll(async () => {
await fs.writeFile(nextConfig, origNextConfig)
await killApp(app)
})
runTests()
})
describe('Font optimization for emulated serverless apps', () => {
const origNextConfig = fs.readFileSync(nextConfig)
beforeAll(async () => {
await fs.writeFile(
nextConfig,
`module.exports = { target: 'experimental-serverless-trace', cleanDistDir: false }`,
`
const path = require('path')
module.exports = require(path.join(__dirname, '../../../../lib/with-react-17.js'))({ target: 'experimental-serverless-trace', cleanDistDir: false })
`,
'utf8'
)
await nextBuild(appDir)
await nextBuild(appDir, undefined, {
nodeArgs,
})
appPort = await findPort()
app = await startServerlessEmulator(appDir, appPort)
app = await startServerlessEmulator(appDir, appPort, {
nodeArgs,
})
builtServerPagesDir = join(appDir, '.next', 'serverless')
builtPage = (file) => join(builtServerPagesDir, file)
})
afterAll(async () => {
await fs.remove(nextConfig)
await fs.writeFile(nextConfig, origNextConfig)
await killApp(app)
})
runTests()
......@@ -288,19 +313,18 @@ describe('Font Optimization', () => {
describe('Font optimization for unreachable font definitions.', () => {
beforeAll(async () => {
await fs.writeFile(
nextConfig,
`module.exports = { cleanDistDir: false }`,
'utf8'
)
await nextBuild(appDir)
await nextBuild(appDir, undefined, {
nodeArgs,
})
await fs.writeFile(
join(appDir, '.next', 'server', 'font-manifest.json'),
'[]',
'utf8'
)
appPort = await findPort()
app = await nextStart(appDir, appPort)
app = await nextStart(appDir, appPort, {
nodeArgs,
})
builtServerPagesDir = join(appDir, '.next', 'serverless')
builtPage = (file) => join(builtServerPagesDir, file)
})
......
......@@ -628,7 +628,7 @@ function responseTests(locale = '') {
`${locale}/responses/react?name=jack`
)
const html = await res.text()
expect(html).toBe('<h1 data-reactroot="">SSR with React! Hello, jack</h1>')
expect(html).toBe('<h1>SSR with React! Hello, jack</h1>')
})
it(`${locale} should stream a React component`, async () => {
......@@ -637,9 +637,7 @@ function responseTests(locale = '') {
`${locale}/responses/react-stream`
)
const html = await res.text()
expect(html).toBe(
'<h1 data-reactroot="">I am a stream</h1><p data-reactroot="">I am another stream</p>'
)
expect(html).toBe('<h1>I am a stream</h1><p>I am another stream</p>')
})
it(`${locale} should stream a long response`, async () => {
......@@ -812,7 +810,9 @@ function interfaceTests(locale = '') {
const element = await browser.elementByCss('.title')
expect(await element.text()).toEqual('Parts page')
const logs = await browser.log()
expect(logs.every((log) => log.source === 'log')).toEqual(true)
expect(
logs.every((log) => log.source === 'log' || log.source === 'info')
).toEqual(true)
})
}
......
......@@ -62,7 +62,7 @@ describe('Middleware usage of dynamic code evaluation', () => {
it('does not has problems with eval in page or server code', async () => {
const html = await renderViaHTTP(context.appPort, `/`)
expect(html).toMatch(/>100<!-- --> and <!-- -->100<\//)
expect(html).toMatch(/>.*?100.*?and.*?100.*?<\//)
await waitFor(500)
expect(output).not.toContain(DYNAMIC_CODE_ERROR)
})
......
......@@ -29,7 +29,9 @@ function runTests() {
const browser = await webdriver(appPort, '/')
const text = await browser.elementByCss('#before-hydration').text()
expect(text).toBe('Index<!-- -->1<!-- -->2<!-- -->3<!-- -->4<!-- -->4')
expect(text).toBe(
'Index<!-- -->1<!-- -->2<!-- -->3<!-- -->4<!-- -->4<!-- -->'
)
expect(await browser.eval('window.caughtErrors')).toBe('')
})
......@@ -37,7 +39,9 @@ function runTests() {
const browser = await webdriver(appPort, '/')
const text = await browser.elementByCss('#first-render').text()
expect(text).toBe('Index<!-- -->1<!-- -->2<!-- -->3<!-- -->4<!-- -->4')
expect(text).toBe(
'Index<!-- -->1<!-- -->2<!-- -->3<!-- -->4<!-- -->4<!-- -->'
)
expect(await browser.eval('window.caughtErrors')).toBe('')
})
}
......
......@@ -29,7 +29,9 @@ function runTests() {
const text = await browser.elementByCss('#first-render').text()
// Failure case is 'Index<!-- -->3<!-- --><!-- -->'
expect(text).toBe('Index<!-- -->1<!-- -->2<!-- -->3<!-- -->4<!-- -->4')
expect(text).toBe(
'Index<!-- -->1<!-- -->2<!-- -->3<!-- -->4<!-- -->4<!-- -->'
)
expect(await browser.eval('window.caughtErrors')).toBe('')
})
}
......
......@@ -377,7 +377,9 @@ describe('Production Usage', () => {
expect(res2.status).toBe(304)
})
it('should allow etag header support with getServerSideProps', async () => {
// TODO: should we generate weak etags for streaming getServerSideProps?
// this is currently not expected to work with react-18
it.skip('should allow etag header support with getServerSideProps', async () => {
const url = `http://localhost:${appPort}`
const etag = (await fetchViaHTTP(url, '/fully-dynamic')).headers.get(
'ETag'
......
......@@ -5,11 +5,17 @@ import { join } from 'path'
import { File, nextBuild } from 'next-test-utils'
const appDir = __dirname
const nodeArgs = ['-r', join(appDir, '../../lib/react-17-require-hook.js')]
const nextConfig = new File(join(appDir, 'next.config.js'))
const reactDomPackagePah = join(appDir, 'node_modules/react-dom')
function writeNextConfig(config) {
const content = `module.exports = { experimental: ${JSON.stringify(config)} }`
const content = `
const path = require('path')
module.exports = require(path.join(__dirname, '../../lib/with-react-17.js'))({ experimental: ${JSON.stringify(
config
)} })
`
nextConfig.write(content)
}
......@@ -18,7 +24,7 @@ describe('Invalid react 18 webpack config', () => {
writeNextConfig({
runtime: 'edge',
})
const { stderr } = await nextBuild(appDir, [], { stderr: true })
const { stderr } = await nextBuild(appDir, [], { stderr: true, nodeArgs })
nextConfig.restore()
expect(stderr).toContain(
......@@ -42,7 +48,7 @@ describe('React 17 with React 18 config', () => {
})
it('should warn user when not using react 18 and `experimental.reactRoot` is enabled', async () => {
const { stderr } = await nextBuild(appDir, [], { stderr: true })
const { stderr } = await nextBuild(appDir, [], { stderr: true, nodeArgs })
expect(stderr).toContain(
'You have to use React 18 to use `experimental.reactRoot`.'
)
......@@ -51,6 +57,7 @@ describe('React 17 with React 18 config', () => {
it('suspense is not allowed in blocking rendering mode', async () => {
const { stderr, code } = await nextBuild(appDir, [], {
stderr: true,
nodeArgs,
})
expect(stderr).toContain(
'Invalid suspense option usage in next/dynamic. Read more: https://nextjs.org/docs/messages/invalid-dynamic-suspense'
......
const withReact18 = require('../test/with-react-18')
module.exports = withReact18({
module.exports = {
// reactStrictMode: true,
experimental: {
reactRoot: true,
......@@ -12,4 +10,4 @@ module.exports = withReact18({
path: 'https://example.com/myaccount/',
loader: 'imgix',
},
})
}
{
"scripts": {
"next": "node -r ../test/require-hook.js ../../../../packages/next/dist/bin/next",
"debug": "NODE_OPTIONS='--inspect' node -r ../../react-18/test/require-hook.js ../../../../packages/next/dist/bin/next",
"dev": "yarn next dev",
"build": "yarn next build",
"start": "yarn next start"
......
......@@ -19,7 +19,7 @@ import strictMode from './strict-mode'
import webdriver from 'next-webdriver'
// overrides react and react-dom to v18
const nodeArgs = ['-r', join(__dirname, 'require-hook.js')]
const nodeArgs = []
const appDir = join(__dirname, '../app')
const nextConfig = new File(join(appDir, 'next.config.js'))
const invalidPage = new File(join(appDir, 'pages/invalid.js'))
......
const withReact18 = require('../../react-18/test/with-react-18')
module.exports = withReact18({
module.exports = {
reactStrictMode: true,
onDemandEntries: {
maxInactiveAge: 1000 * 60 * 60,
......@@ -10,4 +8,4 @@ module.exports = withReact18({
serverComponents: true,
runtime: 'edge',
},
})
}
{
"private": true,
"scripts": {
"lnext": "node -r ../../react-18/test/require-hook.js ../../../../packages/next/dist/bin/next",
"debug": "NODE_OPTIONS='--inspect' node -r ../../react-18/test/require-hook.js ../../../../packages/next/dist/bin/next",
"dev": "yarn lnext dev",
"build": "yarn lnext build",
"start": "yarn lnext start"
"dev": "yarn next dev",
"build": "yarn next build",
"start": "yarn next start"
},
"dependencies": {
"moment": "*"
......
const withReact18 = require('../../react-18/test/with-react-18')
module.exports = withReact18({
module.exports = {
reactStrictMode: true,
experimental: {
serverComponents: true,
// runtime: 'edge',
},
})
}
{
"private": true,
"scripts": {
"lnext": "node -r ../../react-18/test/require-hook.js ../../../../packages/next/dist/bin/next",
"dev": "yarn lnext dev",
"build": "yarn lnext build",
"start": "yarn lnext start"
"dev": "yarn next dev",
"build": "yarn next build",
"start": "yarn next start"
}
}
......@@ -7,7 +7,7 @@ import {
} from 'next-test-utils'
import cheerio from 'cheerio'
const nodeArgs = ['-r', join(__dirname, '../../react-18/test/require-hook.js')]
const nodeArgs = []
export const appDir = join(__dirname, '../app')
export const nativeModuleTestAppDir = join(
......
const withReact18 = require('../../react-18/test/with-react-18')
module.exports = withReact18({
module.exports = {
experimental: {
reactRoot: true,
serverComponents: true,
},
})
}
{
"private": true,
"scripts": {
"lnext": "node -r ../../react-18/test/require-hook.js ../../../../packages/next/dist/bin/next",
"dev": "yarn lnext dev",
"build": "yarn lnext build",
"start": "yarn lnext start"
"dev": "yarn next dev",
"build": "yarn next build",
"start": "yarn next start"
}
}
const path = require('path')
module.exports = require(path.join(__dirname, '../../../lib/with-react-17.js'))(
{}
)
......@@ -12,6 +12,7 @@ import {
} from 'next-test-utils'
const appDir = join(__dirname, '../app')
const nodeArgs = ['-r', join(appDir, '../../../lib/react-17-require-hook.js')]
let appPort
let app
......@@ -48,9 +49,13 @@ function runTests() {
describe('styled-jsx using in node_modules', () => {
describe('Production', () => {
beforeAll(async () => {
await nextBuild(appDir)
await nextBuild(appDir, undefined, {
nodeArgs,
})
appPort = await findPort()
app = await nextStart(appDir, appPort)
app = await nextStart(appDir, appPort, {
nodeArgs,
})
})
afterAll(() => killApp(app))
......@@ -60,7 +65,9 @@ describe('styled-jsx using in node_modules', () => {
describe('Development', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
app = await launchApp(appDir, appPort, {
nodeArgs,
})
})
afterAll(() => killApp(app))
......
......@@ -29,10 +29,14 @@ export function initNextServerScript(
opts
) {
return new Promise((resolve, reject) => {
const instance = spawn('node', ['--no-deprecation', scriptPath], {
env,
cwd: opts && opts.cwd,
})
const instance = spawn(
'node',
[...((opts && opts.nodeArgs) || []), '--no-deprecation', scriptPath],
{
env,
cwd: opts && opts.cwd,
}
)
function handleStdout(data) {
const message = data.toString()
......
const mod = require('module')
const hookPropertyMap = new Map([
['react', 'react-18'],
['react/jsx-runtime', 'react-18/jsx-runtime'],
['react/jsx-dev-runtime', 'react-18/jsx-dev-runtime'],
['react-dom', 'react-dom-18'],
['react-dom/server', 'react-dom-18/server'],
['react-dom/server.browser', 'react-dom-18/server.browser'],
['react', 'react-17'],
['react/jsx-runtime', 'react-17/jsx-runtime'],
['react/jsx-dev-runtime', 'react-17/jsx-dev-runtime'],
['react-dom', 'react-dom-17'],
['react-dom/server', 'react-dom-17/server'],
['react-dom/server.browser', 'react-dom-17/server.browser'],
])
const resolveFilename = mod._resolveFilename
......
module.exports = function withReact18(config) {
module.exports = function withReact17(config) {
config.webpack = (webpackConfig) => {
const { alias } = webpackConfig.resolve
// Use react 18
alias['react'] = 'react-18'
alias['react-dom'] = 'react-dom-18'
alias['react-dom/client'] = 'react-dom-18/client'
alias['react-dom/server'] = 'react-dom-18/server'
alias['react-dom/server.browser'] = 'react-dom-18/server.browser'
alias['react'] = 'react-17'
alias['react-dom'] = 'react-dom-17'
alias['react-dom/client'] = 'react-dom-17/client'
alias['react-dom/server'] = 'react-dom-17/server'
alias['react-dom/server.browser'] = 'react-dom-17/server.browser'
return webpackConfig
}
......
......@@ -14,7 +14,7 @@ describe('Link rendering', () => {
)
const html = ReactDOM.renderToString(element)
expect(html).toMatchInlineSnapshot(
`"<a href=\\"/my-path\\" data-reactroot=\\"\\">to another page</a>"`
`"<a href=\\"/my-path\\">to another page</a>"`
)
})
})
......@@ -4,20 +4,16 @@
import { act, render } from '@testing-library/react'
import Link from 'next/link'
import React from 'react'
import { getPackageVersion } from 'next/dist/lib/get-package-version'
import semver from 'next/dist/compiled/semver'
describe('<Link/>', () => {
let spy
let expectedErrors
beforeAll(async () => {
spy = jest.spyOn(console, 'error').mockImplementation(() => {})
const reactVersion = await getPackageVersion({
cwd: __dirname,
name: 'react-dom',
spy = jest.spyOn(console, 'error').mockImplementation((...args) => {
console.log(...args)
})
expectedErrors = reactVersion && semver.gte(reactVersion, '18.0.0') ? 1 : 0
expectedErrors = 0
})
it('test link with unmount', () => {
......
......@@ -3330,17 +3330,6 @@
"@types/yargs" "^15.0.0"
chalk "^4.0.0"
"@jest/types@^26.6.2":
version "26.6.2"
resolved "https://registry.yarnpkg.com/@jest/types/-/types-26.6.2.tgz#bef5a532030e1d88a2f5a6d933f84e97226ed48e"
integrity sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==
dependencies:
"@types/istanbul-lib-coverage" "^2.0.0"
"@types/istanbul-reports" "^3.0.0"
"@types/node" "*"
"@types/yargs" "^15.0.0"
chalk "^4.0.0"
"@jest/types@^27.0.6":
version "27.0.6"
resolved "https://registry.yarnpkg.com/@jest/types/-/types-27.0.6.tgz#9a992bc517e0c49f035938b8549719c2de40706b"
......@@ -4715,27 +4704,28 @@
dependencies:
chokidar "^1.7.0"
"@testing-library/dom@^7.28.1":
version "7.29.4"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.29.4.tgz#1647c2b478789621ead7a50614ad81ab5ae5b86c"
integrity sha512-CtrJRiSYEfbtNGtEsd78mk1n1v2TUbeABlNIcOCJdDfkN5/JTOwQEbbQpoSRxGqzcWPgStMvJ4mNolSuBRv1NA==
"@testing-library/dom@^8.5.0":
version "8.13.0"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.13.0.tgz#bc00bdd64c7d8b40841e27a70211399ad3af46f5"
integrity sha512-9VHgfIatKNXQNaZTtLnalIy0jNZzY35a4S3oi08YAt9Hv1VsfZ/DfA45lM8D/UhtHBGJ4/lGwp0PZkVndRkoOQ==
dependencies:
"@babel/code-frame" "^7.10.4"
"@babel/runtime" "^7.12.5"
"@types/aria-query" "^4.2.0"
aria-query "^4.2.2"
aria-query "^5.0.0"
chalk "^4.1.0"
dom-accessibility-api "^0.5.4"
dom-accessibility-api "^0.5.9"
lz-string "^1.4.4"
pretty-format "^26.6.2"
pretty-format "^27.0.2"
"@testing-library/react@11.2.5":
version "11.2.5"
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-11.2.5.tgz#ae1c36a66c7790ddb6662c416c27863d87818eb9"
integrity sha512-yEx7oIa/UWLe2F2dqK0FtMF9sJWNXD+2PPtp39BvE0Kh9MJ9Kl0HrZAgEuhUJR+Lx8Di6Xz+rKwSdEPY2UV8ZQ==
"@testing-library/react@13.0.0":
version "13.0.0"
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-13.0.0.tgz#8cdaf4667c6c2b082eb0513731551e9db784e8bc"
integrity sha512-p0lYA1M7uoEmk2LnCbZLGmHJHyH59sAaZVXChTXlyhV/PRW9LoIh4mdf7tiXsO8BoNG+vN8UnFJff1hbZeXv+w==
dependencies:
"@babel/runtime" "^7.12.5"
"@testing-library/dom" "^7.28.1"
"@testing-library/dom" "^8.5.0"
"@types/react-dom" "*"
"@tootallnate/once@1":
version "1.1.2"
......@@ -5233,6 +5223,13 @@
version "1.2.3"
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.3.tgz#7ee330ba7caafb98090bece86a5ee44115904c2c"
"@types/react-dom@*":
version "17.0.14"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.14.tgz#c8f917156b652ddf807711f5becbd2ab018dea9f"
integrity sha512-H03xwEP1oXmSfl3iobtmQ/2dHF5aBHr8aUMwyGZya6OW45G+xtdzmq6HkncefiBt5JU8DVyaWl/nWZbjZCnzAQ==
dependencies:
"@types/react" "*"
"@types/react-dom@16.9.4":
version "16.9.4"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-16.9.4.tgz#0b58df09a60961dcb77f62d4f1832427513420df"
......@@ -6282,6 +6279,11 @@ aria-query@^4.2.2:
"@babel/runtime" "^7.10.2"
"@babel/runtime-corejs3" "^7.10.2"
aria-query@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-5.0.0.tgz#210c21aaf469613ee8c9a62c7f86525e058db52c"
integrity sha512-V+SM7AbUwJ+EBnB8+DXs0hPZHO0W6pqBcc0dW90OwtVG02PswOu/teuARoLQjdDOH+t9pJgGnW5/Qmouf3gPJg==
arr-diff@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-2.0.0.tgz#8f3b827f955a8bd669697e4a4256ac3ceae356cf"
......@@ -9071,10 +9073,10 @@ doctrine@^3.0.0:
dependencies:
esutils "^2.0.2"
dom-accessibility-api@^0.5.4:
version "0.5.4"
resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.4.tgz#b06d059cdd4a4ad9a79275f9d414a5c126241166"
integrity sha512-TvrjBckDy2c6v6RLxPv5QXOnU+SmF9nBII5621Ve5fu6Z/BDrENurBEvlC1f44lKEUVqOpK4w9E5Idc5/EgkLQ==
dom-accessibility-api@^0.5.9:
version "0.5.13"
resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.13.tgz#102ee5f25eacce09bdf1cfa5a298f86da473be4b"
integrity sha512-R305kwb5CcMDIpSHUnLyIAp7SrSPBx6F0VfQFB3M75xVMHhXJJIdePYgbPPh1o57vCHNu5QztokWUPsLjWzFqw==
dom-helpers@^5.1.3:
version "5.2.1"
......@@ -17340,14 +17342,13 @@ pretty-format@^26.0.1:
ansi-styles "^4.0.0"
react-is "^16.12.0"
pretty-format@^26.6.2:
version "26.6.2"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-26.6.2.tgz#e35c2705f14cb7fe2fe94fa078345b444120fc93"
integrity sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==
pretty-format@^27.0.2:
version "27.5.1"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.5.1.tgz#2181879fdea51a7a5851fb39d920faa63f01d88e"
integrity sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==
dependencies:
"@jest/types" "^26.6.2"
ansi-regex "^5.0.0"
ansi-styles "^4.0.0"
ansi-regex "^5.0.1"
ansi-styles "^5.0.0"
react-is "^17.0.1"
pretty-format@^27.0.6:
......@@ -17778,22 +17779,15 @@ rc@^1.0.1, rc@^1.1.6, rc@^1.2.7, rc@^1.2.8:
minimist "^1.2.0"
strip-json-comments "~2.0.1"
"react-18@npm:react@18.0.0":
version "18.0.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.0.0.tgz#b468736d1f4a5891f38585ba8e8fb29f91c3cb96"
integrity sha512-x+VL6wbT4JRVPm7EGxXhZ8w8LTROaxPXOqhlGyVSrv0sB1jkyFGgXxJ8LVoPRLvPR6/CIZGFmfzqUa2NYeMr2A==
dependencies:
loose-envify "^1.1.0"
"react-dom-18@npm:react-dom@18.0.0":
version "18.0.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.0.0.tgz#26b88534f8f1dbb80853e1eabe752f24100d8023"
integrity sha512-XqX7uzmFo0pUceWFCt7Gff6IyIMzFUn7QMZrbrQfGxtaxXZIcGQzoNpRLE3fQLnS4XzLLPMZX2T9TRcSrasicw==
"react-17@npm:react@17.0.2":
version "17.0.2"
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
dependencies:
loose-envify "^1.1.0"
scheduler "^0.21.0"
object-assign "^4.1.1"
react-dom@17.0.2:
"react-dom-17@npm:react-dom@17.0.2":
version "17.0.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==
......@@ -17802,6 +17796,14 @@ react-dom@17.0.2:
object-assign "^4.1.1"
scheduler "^0.20.2"
react-dom@18.0.0:
version "18.0.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.0.0.tgz#26b88534f8f1dbb80853e1eabe752f24100d8023"
integrity sha512-XqX7uzmFo0pUceWFCt7Gff6IyIMzFUn7QMZrbrQfGxtaxXZIcGQzoNpRLE3fQLnS4XzLLPMZX2T9TRcSrasicw==
dependencies:
loose-envify "^1.1.0"
scheduler "^0.21.0"
react-is@17.0.2:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
......@@ -17853,13 +17855,12 @@ react-virtualized@9.22.3:
prop-types "^15.7.2"
react-lifecycles-compat "^3.0.4"
react@17.0.2:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
react@18.0.0:
version "18.0.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.0.0.tgz#b468736d1f4a5891f38585ba8e8fb29f91c3cb96"
integrity sha512-x+VL6wbT4JRVPm7EGxXhZ8w8LTROaxPXOqhlGyVSrv0sB1jkyFGgXxJ8LVoPRLvPR6/CIZGFmfzqUa2NYeMr2A==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
read-cmd-shim@^2.0.0:
version "2.0.0"
......
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