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

Extend support of Pages router to React 18 (#70219)

parent 090dc453
...@@ -202,10 +202,12 @@ jobs: ...@@ -202,10 +202,12 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
group: [1/5, 2/5, 3/5, 4/5, 5/5] group: [1/5, 2/5, 3/5, 4/5, 5/5]
# Empty value uses default
react: ['', '18.3.1']
uses: ./.github/workflows/build_reusable.yml uses: ./.github/workflows/build_reusable.yml
with: with:
afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/test/turbopack-dev-tests-manifest.json" TURBOPACK=1 TURBOPACK_DEV=1 NEXT_E2E_TEST_TIMEOUT=240000 NEXT_TEST_MODE=dev node run-tests.js --test-pattern '^(test\/(development|e2e))/.*\.test\.(js|jsx|ts|tsx)$' --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/test/turbopack-dev-tests-manifest.json" TURBOPACK=1 TURBOPACK_DEV=1 NEXT_E2E_TEST_TIMEOUT=240000 NEXT_TEST_MODE=dev NEXT_TEST_REACT_VERSION="${{ matrix.react }}" node run-tests.js --test-pattern '^(test\/(development|e2e))/.*\.test\.(js|jsx|ts|tsx)$' --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY}
stepName: 'test-turbopack-dev-${{ matrix.group }}' stepName: 'test-turbopack-dev-react-${{ matrix.react }}-${{ matrix.group }}'
secrets: inherit secrets: inherit
test-turbopack-integration: test-turbopack-integration:
...@@ -217,11 +219,13 @@ jobs: ...@@ -217,11 +219,13 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
group: [1/5, 2/5, 3/5, 4/5, 5/5] group: [1/5, 2/5, 3/5, 4/5, 5/5]
# Empty value uses default
react: ['']
uses: ./.github/workflows/build_reusable.yml uses: ./.github/workflows/build_reusable.yml
with: with:
nodeVersion: 18.18.2 nodeVersion: 18.18.2
afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/test/turbopack-dev-tests-manifest.json" TURBOPACK=1 TURBOPACK_DEV=1 node run-tests.js --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} --type integration afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/test/turbopack-dev-tests-manifest.json" TURBOPACK=1 TURBOPACK_DEV=1 NEXT_TEST_REACT_VERSION="${{ matrix.react }}" node run-tests.js --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} --type integration
stepName: 'test-turbopack-integration-${{ matrix.group }}' stepName: 'test-turbopack-integration-react-${{ matrix.react }}-${{ matrix.group }}'
secrets: inherit secrets: inherit
test-turbopack-production: test-turbopack-production:
...@@ -233,11 +237,17 @@ jobs: ...@@ -233,11 +237,17 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
group: [1/5, 2/5, 3/5, 4/5, 5/5] group: [1/5, 2/5, 3/5, 4/5, 5/5]
# Empty value uses default
# TODO: Run with React 18.
# Integration tests use the installed React version in next/package.json.include:
# We can't easily switch like we do for e2e tests.
# Skipping this dimensions until we can figure out a way to test multiple React versions.
react: ['', '18.3.1']
uses: ./.github/workflows/build_reusable.yml uses: ./.github/workflows/build_reusable.yml
with: with:
nodeVersion: 18.18.2 nodeVersion: 18.18.2
afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/test/turbopack-build-tests-manifest.json" TURBOPACK=1 TURBOPACK_BUILD=1 NEXT_TEST_MODE=start node run-tests.js --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} --type production afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/test/turbopack-build-tests-manifest.json" TURBOPACK=1 TURBOPACK_BUILD=1 NEXT_TEST_MODE=start NEXT_TEST_REACT_VERSION="${{ matrix.react }}" node run-tests.js --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} --type production
stepName: 'test-turbopack-production-${{ matrix.group }}' stepName: 'test-turbopack-production-react-${{ matrix.react }}-${{ matrix.group }}'
secrets: inherit secrets: inherit
test-turbopack-production-integration: test-turbopack-production-integration:
...@@ -362,10 +372,12 @@ jobs: ...@@ -362,10 +372,12 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
group: [1/4, 2/4, 3/4, 4/4] group: [1/4, 2/4, 3/4, 4/4]
# Empty value uses default
react: ['', '18.3.1']
uses: ./.github/workflows/build_reusable.yml uses: ./.github/workflows/build_reusable.yml
with: with:
afterBuild: NEXT_TEST_MODE=dev node run-tests.js --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} --type development afterBuild: NEXT_TEST_MODE=dev NEXT_TEST_REACT_VERSION="${{ matrix.react }}" node run-tests.js --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} --type development
stepName: 'test-dev-${{ matrix.group }}' stepName: 'test-dev-react-${{ matrix.react }}-${{ matrix.group }}'
secrets: inherit secrets: inherit
test-prod: test-prod:
...@@ -377,10 +389,12 @@ jobs: ...@@ -377,10 +389,12 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
group: [1/5, 2/5, 3/5, 4/5, 5/5] group: [1/5, 2/5, 3/5, 4/5, 5/5]
# Empty value uses default
react: ['', '18.3.1']
uses: ./.github/workflows/build_reusable.yml uses: ./.github/workflows/build_reusable.yml
with: with:
afterBuild: NEXT_TEST_MODE=start node run-tests.js --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} --type production afterBuild: NEXT_TEST_MODE=start NEXT_TEST_REACT_VERSION="${{ matrix.react }}" node run-tests.js --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} --type production
stepName: 'test-prod-${{ matrix.group }}' stepName: 'test-prod-react-${{ matrix.react }}-${{ matrix.group }}'
secrets: inherit secrets: inherit
test-integration: test-integration:
...@@ -404,11 +418,17 @@ jobs: ...@@ -404,11 +418,17 @@ jobs:
- 10/12 - 10/12
- 11/12 - 11/12
- 12/12 - 12/12
# Empty value uses default
# TODO: Run with React 18.
# Integration tests use the installed React version in next/package.json.include:
# We can't easily switch like we do for e2e tests.
# Skipping this dimensions until we can figure out a way to test multiple React versions.
react: ['']
uses: ./.github/workflows/build_reusable.yml uses: ./.github/workflows/build_reusable.yml
with: with:
nodeVersion: 18.18.2 nodeVersion: 18.18.2
afterBuild: node run-tests.js --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} --type integration afterBuild: NEXT_TEST_REACT_VERSION="${{ matrix.react }}" node run-tests.js --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} --type integration
stepName: 'test-integration-${{ matrix.group }}' stepName: 'test-integration-${{ matrix.group }}-react-${{ matrix.react }}'
secrets: inherit secrets: inherit
test-firefox-safari: test-firefox-safari:
......
...@@ -567,6 +567,15 @@ async fn insert_next_server_special_aliases( ...@@ -567,6 +567,15 @@ async fn insert_next_server_special_aliases(
external_esm_if_node(project_path, "next/dist/compiled/@vercel/og/index.node.js"), external_esm_if_node(project_path, "next/dist/compiled/@vercel/og/index.node.js"),
); );
import_map.insert_exact_alias(
"next/dist/server/ReactDOMServerPages",
ImportMapping::Alternatives(vec![
request_to_import_mapping(project_path, "react-dom/server.edge"),
request_to_import_mapping(project_path, "react-dom/server.browser"),
])
.cell(),
);
import_map.insert_exact_alias( import_map.insert_exact_alias(
"@opentelemetry/api", "@opentelemetry/api",
// It needs to prefer the local version of @opentelemetry/api // It needs to prefer the local version of @opentelemetry/api
......
...@@ -107,8 +107,8 @@ ...@@ -107,8 +107,8 @@
"@opentelemetry/api": "^1.1.0", "@opentelemetry/api": "^1.1.0",
"@playwright/test": "^1.41.2", "@playwright/test": "^1.41.2",
"babel-plugin-react-compiler": "*", "babel-plugin-react-compiler": "*",
"react": "19.0.0-rc-5d19e1c8-20240923", "react": "^18.2.0 || 19.0.0-rc-5d19e1c8-20240923",
"react-dom": "19.0.0-rc-5d19e1c8-20240923", "react-dom": "^18.2.0 || 19.0.0-rc-5d19e1c8-20240923",
"sass": "^1.3.0" "sass": "^1.3.0"
}, },
"peerDependenciesMeta": { "peerDependenciesMeta": {
......
import path from 'path' import path from 'path'
import * as React from 'react'
import { import {
DOT_NEXT_ALIAS, DOT_NEXT_ALIAS,
PAGES_DIR_ALIAS, PAGES_DIR_ALIAS,
...@@ -21,6 +22,8 @@ interface CompilerAliases { ...@@ -21,6 +22,8 @@ interface CompilerAliases {
[alias: string]: string | string[] [alias: string]: string | string[]
} }
const isReact19 = typeof React.use === 'function'
export function createWebpackAliases({ export function createWebpackAliases({
distDir, distDir,
isClient, isClient,
...@@ -90,6 +93,12 @@ export function createWebpackAliases({ ...@@ -90,6 +93,12 @@ export function createWebpackAliases({
return { return {
'@vercel/og$': 'next/dist/server/og/image-response', '@vercel/og$': 'next/dist/server/og/image-response',
// Avoid bundling both entrypoints in React 19 when we just need one.
// Also avoids bundler warnings in React 18 where react-dom/server.edge doesn't exist.
'next/dist/server/ReactDOMServerPages': isReact19
? 'react-dom/server.edge'
: 'react-dom/server.browser',
// Alias next/dist imports to next/dist/esm assets, // Alias next/dist imports to next/dist/esm assets,
// let this alias hit before `next` alias. // let this alias hit before `next` alias.
...(isEdgeServer ...(isEdgeServer
......
...@@ -107,8 +107,8 @@ const NEXT_PROJECT_ROOT_DIST_CLIENT = path.join( ...@@ -107,8 +107,8 @@ const NEXT_PROJECT_ROOT_DIST_CLIENT = path.join(
'client' 'client'
) )
if (parseInt(React.version) < 19) { if (parseInt(React.version) < 18) {
throw new Error('Next.js requires react >= 19.0.0 to be installed.') throw new Error('Next.js requires react >= 18.2.0 to be installed.')
} }
export const babelIncludeRegexes: RegExp[] = [ export const babelIncludeRegexes: RegExp[] = [
......
...@@ -66,7 +66,7 @@ export function PseudoHtmlDiff({ ...@@ -66,7 +66,7 @@ export function PseudoHtmlDiff({
firstContent: string firstContent: string
secondContent: string secondContent: string
reactOutputComponentDiff: string | undefined reactOutputComponentDiff: string | undefined
hydrationMismatchType: 'tag' | 'text' hydrationMismatchType: 'tag' | 'text' | 'text-in-tag'
} & React.HTMLAttributes<HTMLPreElement>) { } & React.HTMLAttributes<HTMLPreElement>) {
const isHtmlTagsWarning = hydrationMismatchType === 'tag' const isHtmlTagsWarning = hydrationMismatchType === 'tag'
const isReactHydrationDiff = !!reactOutputComponentDiff const isReactHydrationDiff = !!reactOutputComponentDiff
......
...@@ -17,21 +17,62 @@ export const hydrationErrorState: HydrationErrorState = {} ...@@ -17,21 +17,62 @@ export const hydrationErrorState: HydrationErrorState = {}
// https://github.com/facebook/react/blob/main/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js used as a reference // https://github.com/facebook/react/blob/main/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js used as a reference
const htmlTagsWarnings = new Set([ const htmlTagsWarnings = new Set([
'In HTML, %s cannot be a child of <%s>.%s\nThis will cause a hydration error.%s', 'Warning: In HTML, %s cannot be a child of <%s>.%s\nThis will cause a hydration error.%s',
'In HTML, %s cannot be a descendant of <%s>.\nThis will cause a hydration error.%s', 'Warning: In HTML, %s cannot be a descendant of <%s>.\nThis will cause a hydration error.%s',
'In HTML, text nodes cannot be a child of <%s>.\nThis will cause a hydration error.', 'Warning: In HTML, text nodes cannot be a child of <%s>.\nThis will cause a hydration error.',
"In HTML, whitespace text nodes cannot be a child of <%s>. Make sure you don't have any extra whitespace between tags on each line of your source code.\nThis will cause a hydration error.", "Warning: In HTML, whitespace text nodes cannot be a child of <%s>. Make sure you don't have any extra whitespace between tags on each line of your source code.\nThis will cause a hydration error.",
'Warning: Expected server HTML to contain a matching <%s> in <%s>.%s',
'Warning: Did not expect server HTML to contain a <%s> in <%s>.%s',
]) ])
const textAndTagsMismatchWarnings = new Set([
'Warning: Expected server HTML to contain a matching text node for "%s" in <%s>.%s',
'Warning: Did not expect server HTML to contain the text node "%s" in <%s>.%s',
])
const textMismatchWarning =
'Warning: Text content did not match. Server: "%s" Client: "%s"%s'
export const getHydrationWarningType = (
message: NullableText
): 'tag' | 'text' | 'text-in-tag' => {
if (typeof message !== 'string') {
// TODO: Doesn't make sense to treat no message as a hydration error message.
// We should bail out somewhere earlier.
return 'text'
}
const normalizedMessage = message.startsWith('Warning: ')
? message
: `Warning: ${message}`
if (isHtmlTagsWarning(normalizedMessage)) return 'tag'
if (isTextInTagsMismatchWarning(normalizedMessage)) return 'text-in-tag'
export const getHydrationWarningType = (msg: NullableText): 'tag' | 'text' => {
if (isHtmlTagsWarning(msg)) return 'tag'
return 'text' return 'text'
} }
const isHtmlTagsWarning = (msg: NullableText) => const isHtmlTagsWarning = (message: string) => htmlTagsWarnings.has(message)
Boolean(msg && htmlTagsWarnings.has(msg))
const isTextMismatchWarning = (message: string) =>
textMismatchWarning === message
const isTextInTagsMismatchWarning = (msg: string) =>
textAndTagsMismatchWarnings.has(msg)
const isKnownHydrationWarning = (msg: NullableText) => isHtmlTagsWarning(msg) const isKnownHydrationWarning = (message: NullableText) => {
if (typeof message !== 'string') {
return false
}
// React 18 has the `Warning: ` prefix.
// React 19 does not.
const normalizedMessage = message.startsWith('Warning: ')
? message
: `Warning: ${message}`
return (
isHtmlTagsWarning(normalizedMessage) ||
isTextInTagsMismatchWarning(normalizedMessage) ||
isTextMismatchWarning(normalizedMessage)
)
}
export const getReactHydrationDiffSegments = (msg: NullableText) => { export const getReactHydrationDiffSegments = (msg: NullableText) => {
if (msg) { if (msg) {
......
...@@ -9,6 +9,8 @@ import React, { ...@@ -9,6 +9,8 @@ import React, {
useState, useState,
type JSX, type JSX,
} from 'react' } from 'react'
import * as ReactDOM from 'react-dom'
import Head from '../../shared/lib/head'
import { import {
imageConfigDefault, imageConfigDefault,
VALID_LOADERS, VALID_LOADERS,
...@@ -26,6 +28,8 @@ function normalizeSrc(src: string): string { ...@@ -26,6 +28,8 @@ function normalizeSrc(src: string): string {
return src[0] === '/' ? src.slice(1) : src return src[0] === '/' ? src.slice(1) : src
} }
const supportsFloat = typeof ReactDOM.preload === 'function'
const configEnv = process.env.__NEXT_IMAGE_OPTS as any as ImageConfigComplete const configEnv = process.env.__NEXT_IMAGE_OPTS as any as ImageConfigComplete
const loadedImageURLs = new Set<string>() const loadedImageURLs = new Set<string>()
const allImgs = new Map< const allImgs = new Map<
...@@ -978,6 +982,20 @@ export default function Image({ ...@@ -978,6 +982,20 @@ export default function Image({
} }
} }
const linkProps:
| React.DetailedHTMLProps<
React.LinkHTMLAttributes<HTMLLinkElement>,
HTMLLinkElement
>
| undefined = supportsFloat
? undefined
: {
imageSrcSet: imgAttributes.srcSet,
imageSizes: imgAttributes.sizes,
crossOrigin: rest.crossOrigin,
referrerPolicy: rest.referrerPolicy,
}
const useLayoutEffect = const useLayoutEffect =
typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect
const onLoadingCompleteRef = useRef(onLoadingComplete) const onLoadingCompleteRef = useRef(onLoadingComplete)
...@@ -1044,6 +1062,27 @@ export default function Image({ ...@@ -1044,6 +1062,27 @@ export default function Image({
) : null} ) : null}
<ImageElement {...imgElementArgs} /> <ImageElement {...imgElementArgs} />
</span> </span>
{!supportsFloat && priority ? (
// Note how we omit the `href` attribute, as it would only be relevant
// for browsers that do not support `imagesrcset`, and in those cases
// it would likely cause the incorrect image to be preloaded.
//
// https://html.spec.whatwg.org/multipage/semantics.html#attr-link-imagesrcset
<Head>
<link
key={
'__nimg-' +
imgAttributes.src +
imgAttributes.srcSet +
imgAttributes.sizes
}
rel="preload"
as="image"
href={imgAttributes.srcSet ? undefined : imgAttributes.src}
{...linkProps}
/>
</Head>
) : null}
</> </>
) )
} }
import { useMemo, type Ref } from 'react' import { useMemo, useRef, type Ref } from 'react'
// This is a compatibility hook to support React 18 and 19 refs.
// In 19, a cleanup function from refs may be returned.
// In 18, returning a cleanup function creates a warning.
// Since we take userspace refs, we don't know ahead of time if a cleanup function will be returned.
// This implements cleanup functions with the old behavior in 18.
// We know refs are always called alternating with `null` and then `T`.
// So a call with `null` means we need to call the previous cleanup functions.
export function useMergedRef<TElement>( export function useMergedRef<TElement>(
refA: Ref<TElement>, refA: Ref<TElement>,
refB: Ref<TElement> refB: Ref<TElement>
): Ref<TElement> { ): Ref<TElement> {
return useMemo(() => mergeRefs(refA, refB), [refA, refB]) const cleanupA = useRef<() => void>(() => {})
} const cleanupB = useRef<() => void>(() => {})
export function mergeRefs<TElement>( return useMemo(() => {
refA: Ref<TElement>,
refB: Ref<TElement>
): Ref<TElement> {
if (!refA || !refB) { if (!refA || !refB) {
return refA || refB return refA || refB
} }
return (current: TElement) => { return (current: TElement | null): void => {
const cleanupA = applyRef(refA, current) if (current === null) {
const cleanupB = applyRef(refB, current) cleanupA.current()
cleanupB.current()
return () => { } else {
cleanupA() cleanupA.current = applyRef(refA, current)
cleanupB() cleanupB.current = applyRef(refB, current)
} }
} }
}, [refA, refB])
} }
function applyRef<TElement>( function applyRef<TElement>(
......
export * from 'react-dom/server.edge'
let ReactDOMServer
try {
ReactDOMServer = require('react-dom/server.edge')
} catch (error) {
if (
error.code !== 'MODULE_NOT_FOUND' &&
error.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED'
) {
throw error
}
// In React versions without react-dom/server.edge, the browser build works in Node.js.
// The Node.js build does not support renderToReadableStream.
ReactDOMServer = require('react-dom/server.browser')
}
module.exports = ReactDOMServer
...@@ -40,7 +40,7 @@ import type { Revalidate, SwrDelta } from './lib/revalidate' ...@@ -40,7 +40,7 @@ import type { Revalidate, SwrDelta } from './lib/revalidate'
import type { COMPILER_NAMES } from '../shared/lib/constants' import type { COMPILER_NAMES } from '../shared/lib/constants'
import React, { type JSX } from 'react' import React, { type JSX } from 'react'
import ReactDOMServerEdge from 'react-dom/server.edge' import ReactDOMServerPages from 'next/dist/server/ReactDOMServerPages'
import { StyleRegistry, createStyleRegistry } from 'styled-jsx' import { StyleRegistry, createStyleRegistry } from 'styled-jsx'
import { import {
GSP_NO_RETURNED_VALUE, GSP_NO_RETURNED_VALUE,
...@@ -127,7 +127,7 @@ function noRouter() { ...@@ -127,7 +127,7 @@ function noRouter() {
} }
async function renderToString(element: React.ReactElement) { async function renderToString(element: React.ReactElement) {
const renderStream = await ReactDOMServerEdge.renderToReadableStream(element) const renderStream = await ReactDOMServerPages.renderToReadableStream(element)
await renderStream.allReady await renderStream.allReady
return streamToString(renderStream) return streamToString(renderStream)
} }
...@@ -1326,7 +1326,7 @@ export async function renderToHTMLImpl( ...@@ -1326,7 +1326,7 @@ export async function renderToHTMLImpl(
) => { ) => {
const content = renderContent(EnhancedApp, EnhancedComponent) const content = renderContent(EnhancedApp, EnhancedComponent)
return await renderToInitialFizzStream({ return await renderToInitialFizzStream({
ReactDOMServer: ReactDOMServerEdge, ReactDOMServer: ReactDOMServerPages,
element: content, element: content,
}) })
} }
......
...@@ -37,6 +37,10 @@ declare module 'VAR_USERLAND' ...@@ -37,6 +37,10 @@ declare module 'VAR_USERLAND'
declare module 'VAR_MODULE_DOCUMENT' declare module 'VAR_MODULE_DOCUMENT'
declare module 'VAR_MODULE_APP' declare module 'VAR_MODULE_APP'
declare module 'next/dist/server/ReactDOMServerPages' {
export * from 'react-dom/server.edge'
}
declare module 'next/dist/compiled/@napi-rs/triples' { declare module 'next/dist/compiled/@napi-rs/triples' {
export * from '@napi-rs/triples' export * from '@napi-rs/triples'
} }
......
...@@ -13,6 +13,7 @@ const pagesExternals = [ ...@@ -13,6 +13,7 @@ const pagesExternals = [
'react-dom/package.json', 'react-dom/package.json',
'react-dom/client', 'react-dom/client',
'react-dom/server', 'react-dom/server',
'react-dom/server.browser',
'react-dom/server.edge', 'react-dom/server.edge',
'react-server-dom-webpack/client', 'react-server-dom-webpack/client',
'react-server-dom-webpack/client.edge', 'react-server-dom-webpack/client.edge',
......
...@@ -330,8 +330,9 @@ Or, run this command with no arguments to use the most recently published versio ...@@ -330,8 +330,9 @@ Or, run this command with no arguments to use the most recently published versio
const nextjsPackageJson = JSON.parse( const nextjsPackageJson = JSON.parse(
await fsp.readFile(nextjsPackageJsonPath, 'utf-8') await fsp.readFile(nextjsPackageJsonPath, 'utf-8')
) )
nextjsPackageJson.peerDependencies.react = `${newVersionStr}` nextjsPackageJson.peerDependencies.react = `^18.2.0 || ${newVersionStr}`
nextjsPackageJson.peerDependencies['react-dom'] = `${newVersionStr}` nextjsPackageJson.peerDependencies['react-dom'] =
`^18.2.0 || ${newVersionStr}`
await fsp.writeFile( await fsp.writeFile(
nextjsPackageJsonPath, nextjsPackageJsonPath,
JSON.stringify(nextjsPackageJson, null, 2) + JSON.stringify(nextjsPackageJson, null, 2) +
......
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
} from 'next-test-utils' } from 'next-test-utils'
const isReactExperimental = process.env.__NEXT_EXPERIMENTAL_PPR === 'true' const isReactExperimental = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('react-dom/server in React Server environment', () => { describe('react-dom/server in React Server environment', () => {
const dependencies = (global as any).isNextDeploy const dependencies = (global as any).isNextDeploy
...@@ -317,6 +318,18 @@ describe('react-dom/server in React Server environment', () => { ...@@ -317,6 +318,18 @@ describe('react-dom/server in React Server environment', () => {
source: await getRedboxSource(browser), source: await getRedboxSource(browser),
} }
if (isTurbopack) { if (isTurbopack) {
if (isReact18) {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": "app/exports/app-code/react-dom-server-node-explicit/page.js (0:0) @ [project]/app/exports/app-code/react-dom-server-node-explicit/page.js [app-rsc] (ecmascript)
1 | import * as ReactDOMServerNode from 'react-dom/server.node'
2 | // Fine to drop once React is on ESM
3 | import ReactDOMServerNodeDefault from 'react-dom/server.node'",
}
`)
} else {
expect(redbox).toMatchInlineSnapshot(` expect(redbox).toMatchInlineSnapshot(`
{ {
"description": "Error: react-dom/server is not supported in React Server Components.", "description": "Error: react-dom/server is not supported in React Server Components.",
...@@ -327,6 +340,15 @@ describe('react-dom/server in React Server environment', () => { ...@@ -327,6 +340,15 @@ describe('react-dom/server in React Server environment', () => {
3 | import ReactDOMServerNodeDefault from 'react-dom/server.node'", 3 | import ReactDOMServerNodeDefault from 'react-dom/server.node'",
} }
`) `)
}
} else {
if (isReact18) {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": null,
}
`)
} else { } else {
expect(redbox).toMatchInlineSnapshot(` expect(redbox).toMatchInlineSnapshot(`
{ {
...@@ -335,6 +357,7 @@ describe('react-dom/server in React Server environment', () => { ...@@ -335,6 +357,7 @@ describe('react-dom/server in React Server environment', () => {
} }
`) `)
} }
}
}) })
it('implicit react-dom/server.node usage in app code', async () => { it('implicit react-dom/server.node usage in app code', async () => {
...@@ -404,6 +427,18 @@ describe('react-dom/server in React Server environment', () => { ...@@ -404,6 +427,18 @@ describe('react-dom/server in React Server environment', () => {
source: await getRedboxSource(browser), source: await getRedboxSource(browser),
} }
if (isTurbopack) { if (isTurbopack) {
if (isReact18) {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": "internal-pkg/server.node.js (0:0) @ [project]/internal-pkg/server.node.js [app-rsc] (ecmascript)
1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
2 | // Fine to drop once React is on ESM
3 | import ReactDOMServerEdgeDefault from 'react-dom/server.node'",
}
`)
} else {
expect(redbox).toMatchInlineSnapshot(` expect(redbox).toMatchInlineSnapshot(`
{ {
"description": "Error: react-dom/server is not supported in React Server Components.", "description": "Error: react-dom/server is not supported in React Server Components.",
...@@ -414,6 +449,15 @@ describe('react-dom/server in React Server environment', () => { ...@@ -414,6 +449,15 @@ describe('react-dom/server in React Server environment', () => {
3 | import ReactDOMServerEdgeDefault from 'react-dom/server.node'", 3 | import ReactDOMServerEdgeDefault from 'react-dom/server.node'",
} }
`) `)
}
} else {
if (isReact18) {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": null,
}
`)
} else { } else {
expect(redbox).toMatchInlineSnapshot(` expect(redbox).toMatchInlineSnapshot(`
{ {
...@@ -422,6 +466,7 @@ describe('react-dom/server in React Server environment', () => { ...@@ -422,6 +466,7 @@ describe('react-dom/server in React Server environment', () => {
} }
`) `)
} }
}
}) })
it('explicit react-dom/server.edge usage in library code', async () => { it('explicit react-dom/server.edge usage in library code', async () => {
...@@ -501,6 +546,7 @@ describe('react-dom/server in React Server environment', () => { ...@@ -501,6 +546,7 @@ describe('react-dom/server in React Server environment', () => {
}" }"
`) `)
} else { } else {
await assertNoRedbox(browser)
expect(await browser.elementByCss('main').text()) expect(await browser.elementByCss('main').text())
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"{ "{
...@@ -675,6 +721,18 @@ describe('react-dom/server in React Server environment', () => { ...@@ -675,6 +721,18 @@ describe('react-dom/server in React Server environment', () => {
source: await getRedboxSource(browser), source: await getRedboxSource(browser),
} }
if (isTurbopack) { if (isTurbopack) {
if (isReact18) {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": "internal-pkg/server.node.js (0:0) @ [project]/internal-pkg/server.node.js [app-rsc] (ecmascript)
1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
2 | // Fine to drop once React is on ESM
3 | import ReactDOMServerEdgeDefault from 'react-dom/server.node'",
}
`)
} else {
expect(redbox).toMatchInlineSnapshot(` expect(redbox).toMatchInlineSnapshot(`
{ {
"description": "Error: react-dom/server is not supported in React Server Components.", "description": "Error: react-dom/server is not supported in React Server Components.",
...@@ -685,6 +743,15 @@ describe('react-dom/server in React Server environment', () => { ...@@ -685,6 +743,15 @@ describe('react-dom/server in React Server environment', () => {
3 | import ReactDOMServerEdgeDefault from 'react-dom/server.node'", 3 | import ReactDOMServerEdgeDefault from 'react-dom/server.node'",
} }
`) `)
}
} else {
if (isReact18) {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": null,
}
`)
} else { } else {
expect(redbox).toMatchInlineSnapshot(` expect(redbox).toMatchInlineSnapshot(`
{ {
...@@ -693,6 +760,7 @@ describe('react-dom/server in React Server environment', () => { ...@@ -693,6 +760,7 @@ describe('react-dom/server in React Server environment', () => {
} }
`) `)
} }
}
}) })
it('implicit react-dom/server.node usage in library code', async () => { it('implicit react-dom/server.node usage in library code', async () => {
...@@ -707,6 +775,18 @@ describe('react-dom/server in React Server environment', () => { ...@@ -707,6 +775,18 @@ describe('react-dom/server in React Server environment', () => {
} }
if (isTurbopack) { if (isTurbopack) {
if (isReact18) {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": "internal-pkg/server.node.js (0:0) @ [project]/internal-pkg/server.node.js [app-rsc] (ecmascript)
1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
2 | // Fine to drop once React is on ESM
3 | import ReactDOMServerEdgeDefault from 'react-dom/server.node'",
}
`)
} else {
expect(redbox).toMatchInlineSnapshot(` expect(redbox).toMatchInlineSnapshot(`
{ {
"description": "Error: react-dom/server is not supported in React Server Components.", "description": "Error: react-dom/server is not supported in React Server Components.",
...@@ -717,6 +797,15 @@ describe('react-dom/server in React Server environment', () => { ...@@ -717,6 +797,15 @@ describe('react-dom/server in React Server environment', () => {
3 | import ReactDOMServerEdgeDefault from 'react-dom/server.node'", 3 | import ReactDOMServerEdgeDefault from 'react-dom/server.node'",
} }
`) `)
}
} else {
if (isReact18) {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": null,
}
`)
} else { } else {
expect(redbox).toMatchInlineSnapshot(` expect(redbox).toMatchInlineSnapshot(`
{ {
...@@ -725,5 +814,6 @@ describe('react-dom/server in React Server environment', () => { ...@@ -725,5 +814,6 @@ describe('react-dom/server in React Server environment', () => {
} }
`) `)
} }
}
}) })
}) })
...@@ -503,7 +503,7 @@ describe('next.rs api', () => { ...@@ -503,7 +503,7 @@ describe('next.rs api', () => {
expect(result.done).toBe(false) expect(result.done).toBe(false)
expect(result.value).toHaveProperty('resource', expect.toBeObject()) expect(result.value).toHaveProperty('resource', expect.toBeObject())
expect(result.value).toHaveProperty('type', 'issues') expect(result.value).toHaveProperty('type', 'issues')
expect(result.value).toHaveProperty('issues', expect.toBeEmpty()) expect(normalizeIssues(result.value.issues)).toEqual([])
expect(result.value).toHaveProperty( expect(result.value).toHaveProperty(
'diagnostics', 'diagnostics',
expect.toBeEmpty() expect.toBeEmpty()
......
...@@ -13,6 +13,8 @@ import webdriver from 'next-webdriver' ...@@ -13,6 +13,8 @@ import webdriver from 'next-webdriver'
import path from 'path' import path from 'path'
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('Client Navigation', () => { describe('Client Navigation', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: path.join(__dirname, 'fixture'), files: path.join(__dirname, 'fixture'),
...@@ -1669,19 +1671,19 @@ describe.each([[false], [true]])( ...@@ -1669,19 +1671,19 @@ describe.each([[false], [true]])(
expect( expect(
Number(await browser.eval('window.__test_async_executions')) Number(await browser.eval('window.__test_async_executions'))
).toBe( ).toBe(
strictNextHead strictNextHead || isReact18
? 1 ? 1
: // <meta name="next-head-count" /> is floated before <script />. : // <meta name="next-head-count" /> is floated before <script />.
// head-manager thinks it needs t add these again resulting in another execution. // head-manager thinks it needs to add these again resulting in another execution.
2 2
) )
expect( expect(
Number(await browser.eval('window.__test_defer_executions')) Number(await browser.eval('window.__test_defer_executions'))
).toBe( ).toBe(
strictNextHead strictNextHead || isReact18
? 1 ? 1
: // <meta name="next-head-count" /> is floated before <script defer />. : // <meta name="next-head-count" /> is floated before <script defer />.
// head-manager thinks it needs t add these again resulting in another execution. // head-manager thinks it needs to add these again resulting in another execution.
2 2
) )
...@@ -1690,20 +1692,20 @@ describe.each([[false], [true]])( ...@@ -1690,20 +1692,20 @@ describe.each([[false], [true]])(
expect( expect(
Number(await browser.eval('window.__test_async_executions')) Number(await browser.eval('window.__test_async_executions'))
).toBe(strictNextHead ? 1 : 2) ).toBe(strictNextHead || isReact18 ? 1 : 2)
expect( expect(
Number(await browser.eval('window.__test_defer_executions')) Number(await browser.eval('window.__test_defer_executions'))
).toBe(strictNextHead ? 1 : 2) ).toBe(strictNextHead || isReact18 ? 1 : 2)
await browser.elementByCss('#toggleScript').click() await browser.elementByCss('#toggleScript').click()
await waitFor(2000) await waitFor(2000)
expect( expect(
Number(await browser.eval('window.__test_async_executions')) Number(await browser.eval('window.__test_async_executions'))
).toBe(strictNextHead ? 1 : 2) ).toBe(strictNextHead || isReact18 ? 1 : 2)
expect( expect(
Number(await browser.eval('window.__test_defer_executions')) Number(await browser.eval('window.__test_defer_executions'))
).toBe(strictNextHead ? 1 : 2) ).toBe(strictNextHead || isReact18 ? 1 : 2)
} finally { } finally {
if (browser) { if (browser) {
await browser.close() await browser.close()
......
...@@ -13,6 +13,8 @@ import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST } from 'next/constants' ...@@ -13,6 +13,8 @@ import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST } from 'next/constants'
import path from 'path' import path from 'path'
import url from 'url' import url from 'url'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('Client Navigation rendering', () => { describe('Client Navigation rendering', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: path.join(__dirname, 'fixture'), files: path.join(__dirname, 'fixture'),
...@@ -609,7 +611,13 @@ describe.each([[false], [true]])( ...@@ -609,7 +611,13 @@ describe.each([[false], [true]])(
const documentHeadElement = const documentHeadElement =
'<meta name="keywords" content="document head test"/>' '<meta name="keywords" content="document head test"/>'
expect(html).toContain(`<head>${nextHeadElement}${documentHeadElement}`) expect(html).toContain(
isReact18
? // charset is not actually at the top.
// data-next-hide-fouc comes first
`</style></noscript>${nextHeadElement}${documentHeadElement}`
: `<head>${nextHeadElement}${documentHeadElement}`
)
}) })
} }
) )
...@@ -7,6 +7,7 @@ import cheerio from 'cheerio' ...@@ -7,6 +7,7 @@ import cheerio from 'cheerio'
// on experimental flags. For example, as a first step we could all the common // on experimental flags. For example, as a first step we could all the common
// gates like this one into a single module. // gates like this one into a single module.
const isPPREnabledByDefault = process.env.__NEXT_EXPERIMENTAL_PPR === 'true' const isPPREnabledByDefault = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
async function resolveStreamResponse(response: any, onData?: any) { async function resolveStreamResponse(response: any, onData?: any) {
let result = '' let result = ''
...@@ -504,8 +505,7 @@ describe('app dir - rsc basics', () => { ...@@ -504,8 +505,7 @@ describe('app dir - rsc basics', () => {
const bundledReactVersionPattern = const bundledReactVersionPattern =
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ? '-experimental-' : '-rc-' process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ? '-experimental-' : '-rc-'
// TODO: (React 19) During Beta, bundled and installed version match. it('should not use bundled react for pages with app', async () => {
it.skip('should not use bundled react for pages with app', async () => {
const ssrPaths = ['/pages-react', '/edge-pages-react'] const ssrPaths = ['/pages-react', '/edge-pages-react']
const promises = ssrPaths.map(async (pathname) => { const promises = ssrPaths.map(async (pathname) => {
const resPages$ = await next.render$(pathname) const resPages$ = await next.render$(pathname)
...@@ -516,7 +516,14 @@ describe('app dir - rsc basics', () => { ...@@ -516,7 +516,14 @@ describe('app dir - rsc basics', () => {
] ]
ssrPagesReactVersions.forEach((version) => { ssrPagesReactVersions.forEach((version) => {
if (isReact18 || isPPREnabledByDefault) {
expect(version).not.toMatch(bundledReactVersionPattern) expect(version).not.toMatch(bundledReactVersionPattern)
} else {
// TODO: Pages router only supports React 19 that is bundled
// Once we run with React 19 stable, this branch should be removed in
// favor of unconditional `not.toMatch`
expect(version).toMatch(bundledReactVersionPattern)
}
}) })
}) })
await Promise.all(promises) await Promise.all(promises)
...@@ -525,7 +532,6 @@ describe('app dir - rsc basics', () => { ...@@ -525,7 +532,6 @@ describe('app dir - rsc basics', () => {
const ssrAppReactVersions = [ const ssrAppReactVersions = [
await resApp$('#react').text(), await resApp$('#react').text(),
await resApp$('#react-dom').text(), await resApp$('#react-dom').text(),
await resApp$('#react-dom-server').text(),
] ]
ssrAppReactVersions.forEach((version) => ssrAppReactVersions.forEach((version) =>
...@@ -550,12 +556,26 @@ describe('app dir - rsc basics', () => { ...@@ -550,12 +556,26 @@ describe('app dir - rsc basics', () => {
] ]
`) `)
browserPagesReactVersions.forEach((version) => browserPagesReactVersions.forEach((version) => {
if (isReact18 || isPPREnabledByDefault) {
expect(version).not.toMatch(bundledReactVersionPattern) expect(version).not.toMatch(bundledReactVersionPattern)
) } else {
browserEdgePagesReactVersions.forEach((version) => // TODO: Pages router only supports React 19 that is bundled
// Once we run with React 19 stable, this branch should be removed in
// favor of unconditional `not.toMatch`
expect(version).toMatch(bundledReactVersionPattern)
}
})
browserEdgePagesReactVersions.forEach((version) => {
if (isReact18 || isPPREnabledByDefault) {
expect(version).not.toMatch(bundledReactVersionPattern) expect(version).not.toMatch(bundledReactVersionPattern)
) } else {
// TODO: Pages router only supports React 19 that is bundled
// Once we run with React 19 stable, this branch should be removed in
// favor of unconditional `not.toMatch`
expect(version).toMatch(bundledReactVersionPattern)
}
})
}) })
it('should use canary react for app', async () => { it('should use canary react for app', async () => {
......
...@@ -3,6 +3,8 @@ import { createNext, FileRef } from 'e2e-utils' ...@@ -3,6 +3,8 @@ import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'e2e-utils' import { NextInstance } from 'e2e-utils'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('prerender native module', () => { describe('prerender native module', () => {
let next: NextInstance let next: NextInstance
...@@ -70,7 +72,9 @@ describe('prerender native module', () => { ...@@ -70,7 +72,9 @@ describe('prerender native module', () => {
/webpack-runtime\.js/, /webpack-runtime\.js/,
/node_modules\/react\/index\.js/, /node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/, /node_modules\/react\/package\.json/,
/node_modules\/react\/cjs\/react\.production\.js/, isReact18
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
], ],
notTests: [], notTests: [],
}, },
...@@ -80,7 +84,9 @@ describe('prerender native module', () => { ...@@ -80,7 +84,9 @@ describe('prerender native module', () => {
/webpack-runtime\.js/, /webpack-runtime\.js/,
/node_modules\/react\/index\.js/, /node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/, /node_modules\/react\/package\.json/,
/node_modules\/react\/cjs\/react\.production\.js/, isReact18
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
/node_modules\/sqlite3\/.*?\.js/, /node_modules\/sqlite3\/.*?\.js/,
/node_modules\/sqlite3\/.*?\.node/, /node_modules\/sqlite3\/.*?\.node/,
/node_modules\/sqlite\/.*?\.js/, /node_modules\/sqlite\/.*?\.js/,
......
...@@ -19,6 +19,8 @@ import { ...@@ -19,6 +19,8 @@ import {
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('Prerender', () => { describe('Prerender', () => {
let next: NextInstance let next: NextInstance
...@@ -2062,7 +2064,9 @@ describe('Prerender', () => { ...@@ -2062,7 +2064,9 @@ describe('Prerender', () => {
/webpack-runtime\.js/, /webpack-runtime\.js/,
/node_modules\/react\/index\.js/, /node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/, /node_modules\/react\/package\.json/,
/node_modules\/react\/cjs\/react\.production\.js/, isReact18
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
], ],
notTests: [], notTests: [],
}, },
...@@ -2073,7 +2077,9 @@ describe('Prerender', () => { ...@@ -2073,7 +2077,9 @@ describe('Prerender', () => {
/chunks\/.*?\.js/, /chunks\/.*?\.js/,
/node_modules\/react\/index\.js/, /node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/, /node_modules\/react\/package\.json/,
/node_modules\/react\/cjs\/react\.production\.js/, isReact18
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
/\/world.txt/, /\/world.txt/,
], ],
notTests: [ notTests: [
...@@ -2088,7 +2094,9 @@ describe('Prerender', () => { ...@@ -2088,7 +2094,9 @@ describe('Prerender', () => {
/chunks\/.*?\.js/, /chunks\/.*?\.js/,
/node_modules\/react\/index\.js/, /node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/, /node_modules\/react\/package\.json/,
/node_modules\/react\/cjs\/react\.production\.js/, isReact18
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
/node_modules\/@firebase\/firestore\/.*?\.js/, /node_modules\/@firebase\/firestore\/.*?\.js/,
], ],
notTests: [/\/world.txt/], notTests: [/\/world.txt/],
...@@ -2109,7 +2117,7 @@ describe('Prerender', () => { ...@@ -2109,7 +2117,7 @@ describe('Prerender', () => {
) )
) )
} catch (error) { } catch (error) {
error.message += `\n\nFiles:\n${files.join('\n')}` error.message += `\n\nPage: ${check.page}\nFiles:\n${files.join('\n')}`
throw error throw error
} }
......
...@@ -21,6 +21,8 @@ import { join } from 'path' ...@@ -21,6 +21,8 @@ import { join } from 'path'
import fs from 'fs/promises' import fs from 'fs/promises'
import { pathExists } from 'fs-extra' import { pathExists } from 'fs-extra'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
let appPort let appPort
...@@ -1180,7 +1182,9 @@ function runTests(mode) { ...@@ -1180,7 +1182,9 @@ function runTests(mode) {
expect(warnings).toEqual([]) expect(warnings).toEqual([])
expect(await browser.elementById('img').getAttribute('src')).toBe(null) expect(await browser.elementById('img').getAttribute('src')).toBe(
isReact18 ? '' : null
)
expect(await browser.elementById('img').getAttribute('srcset')).toBe(null) expect(await browser.elementById('img').getAttribute('srcset')).toBe(null)
expect(await browser.elementById('img').getAttribute('width')).toBe('200') expect(await browser.elementById('img').getAttribute('width')).toBe('200')
expect(await browser.elementById('img').getAttribute('height')).toBe( expect(await browser.elementById('img').getAttribute('height')).toBe(
...@@ -1195,7 +1199,9 @@ function runTests(mode) { ...@@ -1195,7 +1199,9 @@ function runTests(mode) {
) )
expect(warnings).toEqual([]) expect(warnings).toEqual([])
expect(await browser.elementById('img').getAttribute('src')).toBe(null) expect(await browser.elementById('img').getAttribute('src')).toBe(
isReact18 ? '' : null
)
expect(await browser.elementById('img').getAttribute('srcset')).toBe(null) expect(await browser.elementById('img').getAttribute('srcset')).toBe(null)
expect(await browser.elementById('img').getAttribute('width')).toBe('200') expect(await browser.elementById('img').getAttribute('width')).toBe('200')
expect(await browser.elementById('img').getAttribute('height')).toBe( expect(await browser.elementById('img').getAttribute('height')).toBe(
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('custom server', () => { describe('custom server', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
...@@ -28,7 +30,11 @@ describe('custom server', () => { ...@@ -28,7 +30,11 @@ describe('custom server', () => {
it('should render pages with installed react', async () => { it('should render pages with installed react', async () => {
const $ = await next.render$(`/2`) const $ = await next.render$(`/2`)
if (isReact18) {
expect($('body').text()).toMatch(/pages: 18\.\d+\.\d+\{/)
} else {
expect($('body').text()).toMatch(/pages: 19.0.0/) expect($('body').text()).toMatch(/pages: 19.0.0/)
}
}) })
}) })
}) })
......
...@@ -29,6 +29,8 @@ if (process.env.TEST_WASM) { ...@@ -29,6 +29,8 @@ if (process.env.TEST_WASM) {
jest.setTimeout(120 * 1000) jest.setTimeout(120 * 1000)
} }
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('Production Usage', () => { describe('Production Usage', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: path.join(__dirname, '../fixture'), files: path.join(__dirname, '../fixture'),
...@@ -181,7 +183,9 @@ describe('Production Usage', () => { ...@@ -181,7 +183,9 @@ describe('Production Usage', () => {
/webpack-runtime\.js/, /webpack-runtime\.js/,
/node_modules\/react\/index\.js/, /node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/, /node_modules\/react\/package\.json/,
/node_modules\/react\/cjs\/react\.production\.js/, isReact18
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
], ],
notTests: [/\0/, /\?/, /!/], notTests: [/\0/, /\?/, /!/],
}, },
...@@ -192,7 +196,9 @@ describe('Production Usage', () => { ...@@ -192,7 +196,9 @@ describe('Production Usage', () => {
/chunks\/.*?\.js/, /chunks\/.*?\.js/,
/node_modules\/react\/index\.js/, /node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/, /node_modules\/react\/package\.json/,
/node_modules\/react\/cjs\/react\.production\.js/, isReact18
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
/node_modules\/next/, /node_modules\/next/,
], ],
notTests: [/\0/, /\?/, /!/], notTests: [/\0/, /\?/, /!/],
...@@ -204,7 +210,9 @@ describe('Production Usage', () => { ...@@ -204,7 +210,9 @@ describe('Production Usage', () => {
/chunks\/.*?\.js/, /chunks\/.*?\.js/,
/node_modules\/react\/index\.js/, /node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/, /node_modules\/react\/package\.json/,
/node_modules\/react\/cjs\/react\.production\.js/, isReact18
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
/node_modules\/next/, /node_modules\/next/,
/node_modules\/nanoid\/index\.js/, /node_modules\/nanoid\/index\.js/,
/node_modules\/nanoid\/url-alphabet\/index\.js/, /node_modules\/nanoid\/url-alphabet\/index\.js/,
...@@ -219,7 +227,9 @@ describe('Production Usage', () => { ...@@ -219,7 +227,9 @@ describe('Production Usage', () => {
/chunks\/.*?\.js/, /chunks\/.*?\.js/,
/node_modules\/react\/index\.js/, /node_modules\/react\/index\.js/,
/node_modules\/react\/package\.json/, /node_modules\/react\/package\.json/,
/node_modules\/react\/cjs\/react\.production\.js/, isReact18
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
/node_modules\/next/, /node_modules\/next/,
], ],
notTests: [ notTests: [
......
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