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:
fail-fast: false
matrix:
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
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}
stepName: 'test-turbopack-dev-${{ matrix.group }}'
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-react-${{ matrix.react }}-${{ matrix.group }}'
secrets: inherit
test-turbopack-integration:
......@@ -217,11 +219,13 @@ jobs:
fail-fast: false
matrix:
group: [1/5, 2/5, 3/5, 4/5, 5/5]
# Empty value uses default
react: ['']
uses: ./.github/workflows/build_reusable.yml
with:
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
stepName: 'test-turbopack-integration-${{ matrix.group }}'
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-react-${{ matrix.react }}-${{ matrix.group }}'
secrets: inherit
test-turbopack-production:
......@@ -233,11 +237,17 @@ jobs:
fail-fast: false
matrix:
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
with:
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
stepName: 'test-turbopack-production-${{ matrix.group }}'
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-react-${{ matrix.react }}-${{ matrix.group }}'
secrets: inherit
test-turbopack-production-integration:
......@@ -362,10 +372,12 @@ jobs:
fail-fast: false
matrix:
group: [1/4, 2/4, 3/4, 4/4]
# Empty value uses default
react: ['', '18.3.1']
uses: ./.github/workflows/build_reusable.yml
with:
afterBuild: NEXT_TEST_MODE=dev node run-tests.js --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} --type development
stepName: 'test-dev-${{ matrix.group }}'
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-react-${{ matrix.react }}-${{ matrix.group }}'
secrets: inherit
test-prod:
......@@ -377,10 +389,12 @@ jobs:
fail-fast: false
matrix:
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
with:
afterBuild: NEXT_TEST_MODE=start node run-tests.js --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} --type production
stepName: 'test-prod-${{ matrix.group }}'
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-react-${{ matrix.react }}-${{ matrix.group }}'
secrets: inherit
test-integration:
......@@ -404,11 +418,17 @@ jobs:
- 10/12
- 11/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
with:
nodeVersion: 18.18.2
afterBuild: node run-tests.js --timings -g ${{ matrix.group }} -c ${TEST_CONCURRENCY} --type integration
stepName: 'test-integration-${{ matrix.group }}'
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 }}-react-${{ matrix.react }}'
secrets: inherit
test-firefox-safari:
......
......@@ -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"),
);
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(
"@opentelemetry/api",
// It needs to prefer the local version of @opentelemetry/api
......
......@@ -107,8 +107,8 @@
"@opentelemetry/api": "^1.1.0",
"@playwright/test": "^1.41.2",
"babel-plugin-react-compiler": "*",
"react": "19.0.0-rc-5d19e1c8-20240923",
"react-dom": "19.0.0-rc-5d19e1c8-20240923",
"react": "^18.2.0 || 19.0.0-rc-5d19e1c8-20240923",
"react-dom": "^18.2.0 || 19.0.0-rc-5d19e1c8-20240923",
"sass": "^1.3.0"
},
"peerDependenciesMeta": {
......
import path from 'path'
import * as React from 'react'
import {
DOT_NEXT_ALIAS,
PAGES_DIR_ALIAS,
......@@ -21,6 +22,8 @@ interface CompilerAliases {
[alias: string]: string | string[]
}
const isReact19 = typeof React.use === 'function'
export function createWebpackAliases({
distDir,
isClient,
......@@ -90,6 +93,12 @@ export function createWebpackAliases({
return {
'@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,
// let this alias hit before `next` alias.
...(isEdgeServer
......
......@@ -107,8 +107,8 @@ const NEXT_PROJECT_ROOT_DIST_CLIENT = path.join(
'client'
)
if (parseInt(React.version) < 19) {
throw new Error('Next.js requires react >= 19.0.0 to be installed.')
if (parseInt(React.version) < 18) {
throw new Error('Next.js requires react >= 18.2.0 to be installed.')
}
export const babelIncludeRegexes: RegExp[] = [
......
......@@ -66,7 +66,7 @@ export function PseudoHtmlDiff({
firstContent: string
secondContent: string
reactOutputComponentDiff: string | undefined
hydrationMismatchType: 'tag' | 'text'
hydrationMismatchType: 'tag' | 'text' | 'text-in-tag'
} & React.HTMLAttributes<HTMLPreElement>) {
const isHtmlTagsWarning = hydrationMismatchType === 'tag'
const isReactHydrationDiff = !!reactOutputComponentDiff
......
......@@ -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
const htmlTagsWarnings = new Set([
'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',
'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, %s cannot be a child of <%s>.%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',
'Warning: In HTML, text nodes cannot be a child of <%s>.\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'
}
const isHtmlTagsWarning = (msg: NullableText) =>
Boolean(msg && htmlTagsWarnings.has(msg))
const isHtmlTagsWarning = (message: string) => htmlTagsWarnings.has(message)
const isKnownHydrationWarning = (msg: NullableText) => isHtmlTagsWarning(msg)
const isTextMismatchWarning = (message: string) =>
textMismatchWarning === message
const isTextInTagsMismatchWarning = (msg: string) =>
textAndTagsMismatchWarnings.has(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) => {
if (msg) {
......
......@@ -9,6 +9,8 @@ import React, {
useState,
type JSX,
} from 'react'
import * as ReactDOM from 'react-dom'
import Head from '../../shared/lib/head'
import {
imageConfigDefault,
VALID_LOADERS,
......@@ -26,6 +28,8 @@ function normalizeSrc(src: string): string {
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 loadedImageURLs = new Set<string>()
const allImgs = new Map<
......@@ -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 =
typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect
const onLoadingCompleteRef = useRef(onLoadingComplete)
......@@ -1044,6 +1062,27 @@ export default function Image({
) : null}
<ImageElement {...imgElementArgs} />
</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>(
refA: Ref<TElement>,
refB: Ref<TElement>
): Ref<TElement> {
return useMemo(() => mergeRefs(refA, refB), [refA, refB])
}
const cleanupA = useRef<() => void>(() => {})
const cleanupB = useRef<() => void>(() => {})
export function mergeRefs<TElement>(
refA: Ref<TElement>,
refB: Ref<TElement>
): Ref<TElement> {
if (!refA || !refB) {
return refA || refB
}
return (current: TElement) => {
const cleanupA = applyRef(refA, current)
const cleanupB = applyRef(refB, current)
return useMemo(() => {
if (!refA || !refB) {
return refA || refB
}
return () => {
cleanupA()
cleanupB()
return (current: TElement | null): void => {
if (current === null) {
cleanupA.current()
cleanupB.current()
} else {
cleanupA.current = applyRef(refA, current)
cleanupB.current = applyRef(refB, current)
}
}
}
}, [refA, refB])
}
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'
import type { COMPILER_NAMES } from '../shared/lib/constants'
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 {
GSP_NO_RETURNED_VALUE,
......@@ -127,7 +127,7 @@ function noRouter() {
}
async function renderToString(element: React.ReactElement) {
const renderStream = await ReactDOMServerEdge.renderToReadableStream(element)
const renderStream = await ReactDOMServerPages.renderToReadableStream(element)
await renderStream.allReady
return streamToString(renderStream)
}
......@@ -1326,7 +1326,7 @@ export async function renderToHTMLImpl(
) => {
const content = renderContent(EnhancedApp, EnhancedComponent)
return await renderToInitialFizzStream({
ReactDOMServer: ReactDOMServerEdge,
ReactDOMServer: ReactDOMServerPages,
element: content,
})
}
......
......@@ -37,6 +37,10 @@ declare module 'VAR_USERLAND'
declare module 'VAR_MODULE_DOCUMENT'
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' {
export * from '@napi-rs/triples'
}
......
......@@ -13,6 +13,7 @@ const pagesExternals = [
'react-dom/package.json',
'react-dom/client',
'react-dom/server',
'react-dom/server.browser',
'react-dom/server.edge',
'react-server-dom-webpack/client',
'react-server-dom-webpack/client.edge',
......
......@@ -330,8 +330,9 @@ Or, run this command with no arguments to use the most recently published versio
const nextjsPackageJson = JSON.parse(
await fsp.readFile(nextjsPackageJsonPath, 'utf-8')
)
nextjsPackageJson.peerDependencies.react = `${newVersionStr}`
nextjsPackageJson.peerDependencies['react-dom'] = `${newVersionStr}`
nextjsPackageJson.peerDependencies.react = `^18.2.0 || ${newVersionStr}`
nextjsPackageJson.peerDependencies['react-dom'] =
`^18.2.0 || ${newVersionStr}`
await fsp.writeFile(
nextjsPackageJsonPath,
JSON.stringify(nextjsPackageJson, null, 2) +
......
......@@ -503,7 +503,7 @@ describe('next.rs api', () => {
expect(result.done).toBe(false)
expect(result.value).toHaveProperty('resource', expect.toBeObject())
expect(result.value).toHaveProperty('type', 'issues')
expect(result.value).toHaveProperty('issues', expect.toBeEmpty())
expect(normalizeIssues(result.value.issues)).toEqual([])
expect(result.value).toHaveProperty(
'diagnostics',
expect.toBeEmpty()
......
......@@ -13,6 +13,8 @@ import webdriver from 'next-webdriver'
import path from 'path'
import { nextTestSetup } from 'e2e-utils'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('Client Navigation', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, 'fixture'),
......@@ -1669,19 +1671,19 @@ describe.each([[false], [true]])(
expect(
Number(await browser.eval('window.__test_async_executions'))
).toBe(
strictNextHead
strictNextHead || isReact18
? 1
: // <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
)
expect(
Number(await browser.eval('window.__test_defer_executions'))
).toBe(
strictNextHead
strictNextHead || isReact18
? 1
: // <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
)
......@@ -1690,20 +1692,20 @@ describe.each([[false], [true]])(
expect(
Number(await browser.eval('window.__test_async_executions'))
).toBe(strictNextHead ? 1 : 2)
).toBe(strictNextHead || isReact18 ? 1 : 2)
expect(
Number(await browser.eval('window.__test_defer_executions'))
).toBe(strictNextHead ? 1 : 2)
).toBe(strictNextHead || isReact18 ? 1 : 2)
await browser.elementByCss('#toggleScript').click()
await waitFor(2000)
expect(
Number(await browser.eval('window.__test_async_executions'))
).toBe(strictNextHead ? 1 : 2)
).toBe(strictNextHead || isReact18 ? 1 : 2)
expect(
Number(await browser.eval('window.__test_defer_executions'))
).toBe(strictNextHead ? 1 : 2)
).toBe(strictNextHead || isReact18 ? 1 : 2)
} finally {
if (browser) {
await browser.close()
......
......@@ -13,6 +13,8 @@ import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST } from 'next/constants'
import path from 'path'
import url from 'url'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('Client Navigation rendering', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, 'fixture'),
......@@ -609,7 +611,13 @@ describe.each([[false], [true]])(
const documentHeadElement =
'<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'
// on experimental flags. For example, as a first step we could all the common
// gates like this one into a single module.
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) {
let result = ''
......@@ -504,8 +505,7 @@ describe('app dir - rsc basics', () => {
const bundledReactVersionPattern =
process.env.__NEXT_EXPERIMENTAL_PPR === 'true' ? '-experimental-' : '-rc-'
// TODO: (React 19) During Beta, bundled and installed version match.
it.skip('should not use bundled react for pages with app', async () => {
it('should not use bundled react for pages with app', async () => {
const ssrPaths = ['/pages-react', '/edge-pages-react']
const promises = ssrPaths.map(async (pathname) => {
const resPages$ = await next.render$(pathname)
......@@ -516,7 +516,14 @@ describe('app dir - rsc basics', () => {
]
ssrPagesReactVersions.forEach((version) => {
expect(version).not.toMatch(bundledReactVersionPattern)
if (isReact18 || isPPREnabledByDefault) {
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)
......@@ -525,7 +532,6 @@ describe('app dir - rsc basics', () => {
const ssrAppReactVersions = [
await resApp$('#react').text(),
await resApp$('#react-dom').text(),
await resApp$('#react-dom-server').text(),
]
ssrAppReactVersions.forEach((version) =>
......@@ -550,12 +556,26 @@ describe('app dir - rsc basics', () => {
]
`)
browserPagesReactVersions.forEach((version) =>
expect(version).not.toMatch(bundledReactVersionPattern)
)
browserEdgePagesReactVersions.forEach((version) =>
expect(version).not.toMatch(bundledReactVersionPattern)
)
browserPagesReactVersions.forEach((version) => {
if (isReact18 || isPPREnabledByDefault) {
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)
}
})
browserEdgePagesReactVersions.forEach((version) => {
if (isReact18 || isPPREnabledByDefault) {
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 () => {
......
......@@ -3,6 +3,8 @@ import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'e2e-utils'
import webdriver from 'next-webdriver'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('prerender native module', () => {
let next: NextInstance
......@@ -70,7 +72,9 @@ describe('prerender native module', () => {
/webpack-runtime\.js/,
/node_modules\/react\/index\.js/,
/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: [],
},
......@@ -80,7 +84,9 @@ describe('prerender native module', () => {
/webpack-runtime\.js/,
/node_modules\/react\/index\.js/,
/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\/.*?\.node/,
/node_modules\/sqlite\/.*?\.js/,
......
......@@ -19,6 +19,8 @@ import {
import webdriver from 'next-webdriver'
import stripAnsi from 'strip-ansi'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('Prerender', () => {
let next: NextInstance
......@@ -2062,7 +2064,9 @@ describe('Prerender', () => {
/webpack-runtime\.js/,
/node_modules\/react\/index\.js/,
/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: [],
},
......@@ -2073,7 +2077,9 @@ describe('Prerender', () => {
/chunks\/.*?\.js/,
/node_modules\/react\/index\.js/,
/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/,
],
notTests: [
......@@ -2088,7 +2094,9 @@ describe('Prerender', () => {
/chunks\/.*?\.js/,
/node_modules\/react\/index\.js/,
/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/,
],
notTests: [/\/world.txt/],
......@@ -2109,7 +2117,7 @@ describe('Prerender', () => {
)
)
} catch (error) {
error.message += `\n\nFiles:\n${files.join('\n')}`
error.message += `\n\nPage: ${check.page}\nFiles:\n${files.join('\n')}`
throw error
}
......
......@@ -21,6 +21,8 @@ import { join } from 'path'
import fs from 'fs/promises'
import { pathExists } from 'fs-extra'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
const appDir = join(__dirname, '../')
let appPort
......@@ -1180,7 +1182,9 @@ function runTests(mode) {
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('width')).toBe('200')
expect(await browser.elementById('img').getAttribute('height')).toBe(
......@@ -1195,7 +1199,9 @@ function runTests(mode) {
)
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('width')).toBe('200')
expect(await browser.elementById('img').getAttribute('height')).toBe(
......
import { nextTestSetup } from 'e2e-utils'
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('custom server', () => {
const { next } = nextTestSetup({
files: __dirname,
......@@ -28,7 +30,11 @@ describe('custom server', () => {
it('should render pages with installed react', async () => {
const $ = await next.render$(`/2`)
expect($('body').text()).toMatch(/pages: 19.0.0/)
if (isReact18) {
expect($('body').text()).toMatch(/pages: 18\.\d+\.\d+\{/)
} else {
expect($('body').text()).toMatch(/pages: 19.0.0/)
}
})
})
})
......
......@@ -29,6 +29,8 @@ if (process.env.TEST_WASM) {
jest.setTimeout(120 * 1000)
}
const isReact18 = parseInt(process.env.NEXT_TEST_REACT_VERSION) === 18
describe('Production Usage', () => {
const { next } = nextTestSetup({
files: path.join(__dirname, '../fixture'),
......@@ -181,7 +183,9 @@ describe('Production Usage', () => {
/webpack-runtime\.js/,
/node_modules\/react\/index\.js/,
/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/, /\?/, /!/],
},
......@@ -192,7 +196,9 @@ describe('Production Usage', () => {
/chunks\/.*?\.js/,
/node_modules\/react\/index\.js/,
/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/,
],
notTests: [/\0/, /\?/, /!/],
......@@ -204,7 +210,9 @@ describe('Production Usage', () => {
/chunks\/.*?\.js/,
/node_modules\/react\/index\.js/,
/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\/nanoid\/index\.js/,
/node_modules\/nanoid\/url-alphabet\/index\.js/,
......@@ -219,7 +227,9 @@ describe('Production Usage', () => {
/chunks\/.*?\.js/,
/node_modules\/react\/index\.js/,
/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/,
],
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