Unverified Commit 69f07b68 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Revert "Support React 18 in Pages Router" (#69911)

Reverts vercel/next.js#69484
parent fcde8fc1
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
}, },
"dependencies": { "dependencies": {
"next": "canary", "next": "canary",
"react": "^18.2.0", "react": "19.0.0-rc-7771d3a7-20240827",
"react-dom": "^18.2.0" "react-dom": "19.0.0-rc-7771d3a7-20240827"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "20.12.12", "@types/node": "20.12.12",
......
...@@ -206,10 +206,10 @@ ...@@ -206,10 +206,10 @@
"pretty-bytes": "5.3.0", "pretty-bytes": "5.3.0",
"pretty-ms": "7.0.0", "pretty-ms": "7.0.0",
"random-seed": "0.3.0", "random-seed": "0.3.0",
"react": "18.3.1", "react": "19.0.0-rc-7771d3a7-20240827",
"react-17": "npm:react@17.0.2", "react-17": "npm:react@17.0.2",
"react-builtin": "npm:react@19.0.0-rc-7771d3a7-20240827", "react-builtin": "npm:react@19.0.0-rc-7771d3a7-20240827",
"react-dom": "18.3.1", "react-dom": "19.0.0-rc-7771d3a7-20240827",
"react-dom-17": "npm:react-dom@17.0.2", "react-dom-17": "npm:react-dom@17.0.2",
"react-dom-builtin": "npm:react-dom@19.0.0-rc-7771d3a7-20240827", "react-dom-builtin": "npm:react-dom@19.0.0-rc-7771d3a7-20240827",
"react-dom-experimental-builtin": "npm:react-dom@0.0.0-experimental-7771d3a7-20240827", "react-dom-experimental-builtin": "npm:react-dom@0.0.0-experimental-7771d3a7-20240827",
...@@ -269,10 +269,10 @@ ...@@ -269,10 +269,10 @@
"@babel/traverse": "7.22.5", "@babel/traverse": "7.22.5",
"@types/react": "npm:types-react@19.0.0-rc.0", "@types/react": "npm:types-react@19.0.0-rc.0",
"@types/react-dom": "npm:types-react-dom@19.0.0-rc.0", "@types/react-dom": "npm:types-react-dom@19.0.0-rc.0",
"react": "18.3.1", "react": "19.0.0-rc-7771d3a7-20240827",
"react-dom": "18.3.1", "react-dom": "19.0.0-rc-7771d3a7-20240827",
"react-is": "18.3.1", "react-is": "19.0.0-rc-7771d3a7-20240827",
"scheduler": "0.23.2" "scheduler": "0.25.0-rc-7771d3a7-20240827"
}, },
"patchedDependencies": { "patchedDependencies": {
"webpack-sources@3.2.3": "patches/webpack-sources@3.2.3.patch" "webpack-sources@3.2.3": "patches/webpack-sources@3.2.3.patch"
......
...@@ -13,7 +13,7 @@ import { GetTemplateFileArgs, InstallTemplateArgs } from "./types"; ...@@ -13,7 +13,7 @@ import { GetTemplateFileArgs, InstallTemplateArgs } from "./types";
// Do not rename or format. sync-react script relies on this line. // Do not rename or format. sync-react script relies on this line.
// prettier-ignore // prettier-ignore
const nextjsReactPeerVersion = "^18.2.0"; const nextjsReactPeerVersion = "19.0.0-rc-7771d3a7-20240827";
/** /**
* Get the file path for a given file in a template, e.g. "next.config.js". * Get the file path for a given file in a template, e.g. "next.config.js".
......
...@@ -108,8 +108,8 @@ ...@@ -108,8 +108,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": "^18.2.0", "react": "19.0.0-rc-7771d3a7-20240827",
"react-dom": "^18.2.0", "react-dom": "19.0.0-rc-7771d3a7-20240827",
"sass": "^1.3.0" "sass": "^1.3.0"
}, },
"peerDependenciesMeta": { "peerDependenciesMeta": {
......
...@@ -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) !== 18) { if (parseInt(React.version) < 19) {
throw new Error('Next.js requires react@^18.2.0 to be installed.') throw new Error('Next.js requires react >= 19.0.0 to be installed.')
} }
export const babelIncludeRegexes: RegExp[] = [ export const babelIncludeRegexes: RegExp[] = [
......
...@@ -238,6 +238,7 @@ export function Errors({ ...@@ -238,6 +238,7 @@ export function Errors({
) )
const errorDetails: HydrationErrorState = (error as any).details || {} const errorDetails: HydrationErrorState = (error as any).details || {}
const notes = errorDetails.notes || ''
const [warningTemplate, serverContent, clientContent] = const [warningTemplate, serverContent, clientContent] =
errorDetails.warning || [null, '', ''] errorDetails.warning || [null, '', '']
...@@ -251,7 +252,6 @@ export function Errors({ ...@@ -251,7 +252,6 @@ export function Errors({
.replace(/^Warning: /, '') .replace(/^Warning: /, '')
.replace(/^Error: /, '') .replace(/^Error: /, '')
: null : null
const notes = isAppDir ? errorDetails.notes || '' : hydrationWarning
return ( return (
<Overlay> <Overlay>
...@@ -307,9 +307,7 @@ export function Errors({ ...@@ -307,9 +307,7 @@ export function Errors({
{/* If there's hydration warning, skip displaying the error name */} {/* If there's hydration warning, skip displaying the error name */}
{hydrationWarning ? '' : error.name + ': '} {hydrationWarning ? '' : error.name + ': '}
<HotlinkedText <HotlinkedText
text={ text={hydrationWarning || error.message}
isAppDir ? hydrationWarning || error.message : error.message
}
matcher={isNextjsLink} matcher={isNextjsLink}
/> />
</p> </p>
......
...@@ -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' | 'text-in-tag' hydrationMismatchType: 'tag' | 'text'
} & React.HTMLAttributes<HTMLPreElement>) { } & React.HTMLAttributes<HTMLPreElement>) {
const isHtmlTagsWarning = hydrationMismatchType === 'tag' const isHtmlTagsWarning = hydrationMismatchType === 'tag'
const isReactHydrationDiff = !!reactOutputComponentDiff const isReactHydrationDiff = !!reactOutputComponentDiff
......
...@@ -23,42 +23,15 @@ const htmlTagsWarnings = new Set([ ...@@ -23,42 +23,15 @@ const htmlTagsWarnings = new Set([
"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.", "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.",
]) ])
// In React 18, the warning message is prefixed with "Warning: " export const getHydrationWarningType = (msg: NullableText): 'tag' | 'text' => {
const normalizeWarningMessage = (msg: string) => msg.replace(/^Warning: /, '')
// Note: React 18 only
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',
])
// Note: React 18 only
const textMismatchWarning =
'Warning: Text content did not match. Server: "%s" Client: "%s"%s'
const isTextMismatchWarning = (msg: NullableText) => textMismatchWarning === msg
const isTextInTagsMismatchWarning = (msg: NullableText) =>
Boolean(msg && textAndTagsMismatchWarnings.has(msg))
export const getHydrationWarningType = (
msg: NullableText
): 'tag' | 'text' | 'text-in-tag' => {
if (isHtmlTagsWarning(msg)) return 'tag' if (isHtmlTagsWarning(msg)) return 'tag'
return 'text' return 'text'
} }
const isHtmlTagsWarning = (msg: NullableText) => { const isHtmlTagsWarning = (msg: NullableText) =>
if (msg && typeof msg === 'string') { Boolean(msg && htmlTagsWarnings.has(msg))
return htmlTagsWarnings.has(normalizeWarningMessage(msg))
}
return false
}
const isKnownHydrationWarning = (msg: NullableText) => const isKnownHydrationWarning = (msg: NullableText) => isHtmlTagsWarning(msg)
isHtmlTagsWarning(msg) ||
isTextInTagsMismatchWarning(msg) ||
isTextMismatchWarning(msg)
export const getReactHydrationDiffSegments = (msg: NullableText) => { export const getReactHydrationDiffSegments = (msg: NullableText) => {
if (msg) { if (msg) {
...@@ -78,18 +51,14 @@ export const getReactHydrationDiffSegments = (msg: NullableText) => { ...@@ -78,18 +51,14 @@ export const getReactHydrationDiffSegments = (msg: NullableText) => {
export function storeHydrationErrorStateFromConsoleArgs(...args: any[]) { export function storeHydrationErrorStateFromConsoleArgs(...args: any[]) {
const [msg, serverContent, clientContent, componentStack] = args const [msg, serverContent, clientContent, componentStack] = args
if (isKnownHydrationWarning(msg)) { if (isKnownHydrationWarning(msg)) {
hydrationErrorState.warning = [msg, serverContent, clientContent] hydrationErrorState.warning = [
// remove the last %s from the message
msg,
serverContent,
clientContent,
]
hydrationErrorState.componentStack = componentStack hydrationErrorState.componentStack = componentStack
hydrationErrorState.serverContent = serverContent hydrationErrorState.serverContent = serverContent
hydrationErrorState.clientContent = clientContent hydrationErrorState.clientContent = clientContent
return [
...args,
// We tack on the hydration error message to the console.error message so that
// it matches the error we display in the redbox overlay
`\nSee more info here: https://nextjs.org/docs/messages/react-hydration-error`,
]
} }
return args
} }
...@@ -52,13 +52,11 @@ function handleError(error: unknown) { ...@@ -52,13 +52,11 @@ function handleError(error: unknown) {
let origConsoleError = console.error let origConsoleError = console.error
function nextJsHandleConsoleError(...args: any[]) { function nextJsHandleConsoleError(...args: any[]) {
// To support React 19, this will need to be updated as follows:
// const error = process.env.NODE_ENV !== 'production' ? args[1] : args[0]
// See https://github.com/facebook/react/blob/d50323eb845c5fde0d720cae888bf35dedd05506/packages/react-reconciler/src/ReactFiberErrorLogger.js#L78 // See https://github.com/facebook/react/blob/d50323eb845c5fde0d720cae888bf35dedd05506/packages/react-reconciler/src/ReactFiberErrorLogger.js#L78
const error = args[0] const error = process.env.NODE_ENV !== 'production' ? args[1] : args[0]
const errorArgs = storeHydrationErrorStateFromConsoleArgs(...args) storeHydrationErrorStateFromConsoleArgs(...args)
handleError(error) handleError(error)
origConsoleError.apply(window.console, errorArgs) origConsoleError.apply(window.console, args)
} }
function onUnhandledError(event: ErrorEvent) { function onUnhandledError(event: ErrorEvent) {
......
...@@ -9,8 +9,6 @@ import React, { ...@@ -9,8 +9,6 @@ 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,
...@@ -28,8 +26,6 @@ function normalizeSrc(src: string): string { ...@@ -28,8 +26,6 @@ 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<
...@@ -982,20 +978,6 @@ export default function Image({ ...@@ -982,20 +978,6 @@ 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)
...@@ -1062,27 +1044,6 @@ export default function Image({ ...@@ -1062,27 +1044,6 @@ 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, useRef, type Ref } from 'react' import { useMemo, 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> {
const cleanupA = useRef<() => void>(() => {}) return useMemo(() => mergeRefs(refA, refB), [refA, refB])
const cleanupB = useRef<() => void>(() => {}) }
return useMemo(() => { export function mergeRefs<TElement>(
if (!refA || !refB) { refA: Ref<TElement>,
return refA || refB 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 (current: TElement | null): void => { return () => {
if (current === null) { cleanupA()
cleanupA.current() cleanupB()
cleanupB.current()
} else {
cleanupA.current = applyRef(refA, current)
cleanupB.current = applyRef(refB, current)
}
} }
}, [refA, refB]) }
} }
function applyRef<TElement>( function applyRef<TElement>(
......
(()=>{var t={302:t=>{function n(t,i){for(var _ in i)t[_]=i[_];return t}t.exports=function(t){var i=[];function u(t){for(var _=[],a=0;a<i.length;a++)i[a]===t?t=null:_.push(i[a]);i=_}function e(_,a,f){t=a?_:n(n({},t),_);for(var o=i,c=0;c<o.length;c++)o[c](t,f)}return t=t||{},{action:function(i){function r(t){e(t,!1,i)}return function(){for(var _=arguments,a=[t],f=0;f<arguments.length;f++)a.push(_[f]);var o=i.apply(this,a);if(null!=o)return o.then?o.then(r):r(o)}},setState:e,subscribe:function(t){return i.push(t),function(){u(t)}},unsubscribe:u,getState:function(){return t}}}}};var i={};function __nccwpck_require__(_){var a=i[_];if(a!==undefined){return a.exports}var f=i[_]={exports:{}};var o=true;try{t[_](f,f.exports,__nccwpck_require__);o=false}finally{if(o)delete i[_]}return f.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var _=__nccwpck_require__(302);module.exports=_})(); (()=>{var t={583:t=>{function n(t,i){for(var _ in i)t[_]=i[_];return t}t.exports=function(t){var i=[];function u(t){for(var _=[],a=0;a<i.length;a++)i[a]===t?t=null:_.push(i[a]);i=_}function e(_,a,f){t=a?_:n(n({},t),_);for(var o=i,c=0;c<o.length;c++)o[c](t,f)}return t=t||{},{action:function(i){function r(t){e(t,!1,i)}return function(){for(var _=arguments,a=[t],f=0;f<arguments.length;f++)a.push(_[f]);var o=i.apply(this,a);if(null!=o)return o.then?o.then(r):r(o)}},setState:e,subscribe:function(t){return i.push(t),function(){u(t)}},unsubscribe:u,getState:function(){return t}}}}};var i={};function __nccwpck_require__(_){var a=i[_];if(a!==undefined){return a.exports}var f=i[_]={exports:{}};var o=true;try{t[_](f,f.exports,__nccwpck_require__);o=false}finally{if(o)delete i[_]}return f.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var _=__nccwpck_require__(583);module.exports=_})();
\ No newline at end of file \ No newline at end of file
...@@ -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 ReactDOMServerBrowser from 'react-dom/server.browser' import ReactDOMServerEdge from 'react-dom/server.edge'
import { StyleRegistry, createStyleRegistry } from 'styled-jsx' import { StyleRegistry, createStyleRegistry } from 'styled-jsx'
import { import {
GSP_NO_RETURNED_VALUE, GSP_NO_RETURNED_VALUE,
...@@ -127,8 +127,7 @@ function noRouter() { ...@@ -127,8 +127,7 @@ function noRouter() {
} }
async function renderToString(element: React.ReactElement) { async function renderToString(element: React.ReactElement) {
const renderStream = const renderStream = await ReactDOMServerEdge.renderToReadableStream(element)
await ReactDOMServerBrowser.renderToReadableStream(element)
await renderStream.allReady await renderStream.allReady
return streamToString(renderStream) return streamToString(renderStream)
} }
...@@ -1323,7 +1322,7 @@ export async function renderToHTMLImpl( ...@@ -1323,7 +1322,7 @@ export async function renderToHTMLImpl(
) => { ) => {
const content = renderContent(EnhancedApp, EnhancedComponent) const content = renderContent(EnhancedApp, EnhancedComponent)
return await renderToInitialFizzStream({ return await renderToInitialFizzStream({
ReactDOMServer: ReactDOMServerBrowser, ReactDOMServer: ReactDOMServerEdge,
element: content, element: content,
}) })
} }
......
...@@ -70,10 +70,6 @@ declare module 'react-dom/server.edge' { ...@@ -70,10 +70,6 @@ declare module 'react-dom/server.edge' {
> >
} }
declare module 'react-dom/server.browser' {
export * from 'react-dom/server.edge'
}
declare module 'react-dom/static.edge' { declare module 'react-dom/static.edge' {
import type { JSX } from 'react' import type { JSX } from 'react'
/** /**
......
...@@ -13,7 +13,6 @@ const pagesExternals = [ ...@@ -13,7 +13,6 @@ 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',
......
This diff is collapsed.
...@@ -18,10 +18,9 @@ const exec = promisify(execOrig) ...@@ -18,10 +18,9 @@ const exec = promisify(execOrig)
const core = require('@actions/core') const core = require('@actions/core')
const { getTestFilter } = require('./test/get-test-filter') const { getTestFilter } = require('./test/get-test-filter')
// TODO: Base this off of test matrix
// Do not rename or format. sync-react script relies on this line. // Do not rename or format. sync-react script relies on this line.
// prettier-ignore // prettier-ignore
const nextjsReactPeerVersion = "^18.2.0"; const nextjsReactPeerVersion = "19.0.0-rc-7771d3a7-20240827";
let argv = require('yargs/yargs')(process.argv.slice(2)) let argv = require('yargs/yargs')(process.argv.slice(2))
.string('type') .string('type')
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"next": "latest", "next": "latest",
"react": "^18.2.0", "react": "19.0.0-rc-7771d3a7-20240827",
"react-dom": "^18.2.0" "react-dom": "19.0.0-rc-7771d3a7-20240827"
}, },
"engines": { "engines": {
"node": ">=18.18.0" "node": ">=18.18.0"
......
...@@ -4,8 +4,7 @@ import { FileRef, nextTestSetup } from 'e2e-utils' ...@@ -4,8 +4,7 @@ import { FileRef, nextTestSetup } from 'e2e-utils'
import { outdent } from 'outdent' import { outdent } from 'outdent'
import path from 'path' import path from 'path'
// TODO: Enable once React 19 support is added to pages. describe('Error overlay for hydration errors (React 19)', () => {
describe.skip('Error overlay for hydration errors (React 19)', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')), files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true, skipStart: true,
......
...@@ -4,7 +4,8 @@ import { FileRef, nextTestSetup } from 'e2e-utils' ...@@ -4,7 +4,8 @@ import { FileRef, nextTestSetup } from 'e2e-utils'
import { outdent } from 'outdent' import { outdent } from 'outdent'
import path from 'path' import path from 'path'
describe('Error overlay for hydration errors (React 18)', () => { // TODO: Enable this test once react 18 is supported for pages router
describe.skip('Error overlay for hydration errors (React 18)', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')), files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: { dependencies: {
...@@ -37,7 +38,7 @@ describe('Error overlay for hydration errors (React 18)', () => { ...@@ -37,7 +38,7 @@ describe('Error overlay for hydration errors (React 18)', () => {
await session.assertHasRedbox() await session.assertHasRedbox()
expect(await session.getRedboxDescription()).toMatchInlineSnapshot(` expect(await session.getRedboxDescription()).toMatchInlineSnapshot(`
"Text content does not match server-rendered HTML. "Error: Text content does not match server-rendered HTML.
See more info here: https://nextjs.org/docs/messages/react-hydration-error" See more info here: https://nextjs.org/docs/messages/react-hydration-error"
`) `)
......
...@@ -18,8 +18,6 @@ import { NextInstance } from 'e2e-utils' ...@@ -18,8 +18,6 @@ import { NextInstance } from 'e2e-utils'
import { outdent } from 'outdent' import { outdent } from 'outdent'
import type { NextConfig } from 'next' import type { NextConfig } from 'next'
const isReact18 = true
describe.each([ describe.each([
{ basePath: '', assetPrefix: '' }, { basePath: '', assetPrefix: '' },
{ basePath: '', assetPrefix: '/asset-prefix' }, { basePath: '', assetPrefix: '/asset-prefix' },
...@@ -43,14 +41,11 @@ describe.each([ ...@@ -43,14 +41,11 @@ describe.each([
}) })
await retry(async () => { await retry(async () => {
const logs = await browser.log() const logs = await browser.log()
expect(logs).toEqual( expect(logs).toEqual(
expect.arrayContaining([ expect.arrayContaining([
{ {
message: expect.stringContaining( message: expect.stringContaining(
isReact18 'https://react.dev/link/hydration-mismatch'
? 'https://nextjs.org/docs/messages/react-hydration-error'
: 'https://react.dev/link/hydration-mismatch'
), ),
source: 'error', source: 'error',
}, },
......
...@@ -13,8 +13,6 @@ import webdriver from 'next-webdriver' ...@@ -13,8 +13,6 @@ 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 = true
describe('Client Navigation', () => { describe('Client Navigation', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: path.join(__dirname, 'fixture'), files: path.join(__dirname, 'fixture'),
...@@ -1671,19 +1669,19 @@ describe.each([[false], [true]])( ...@@ -1671,19 +1669,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 || isReact18 strictNextHead
? 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 to add these again resulting in another execution. // head-manager thinks it needs t 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 || isReact18 strictNextHead
? 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 to add these again resulting in another execution. // head-manager thinks it needs t add these again resulting in another execution.
2 2
) )
...@@ -1692,20 +1690,20 @@ describe.each([[false], [true]])( ...@@ -1692,20 +1690,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 || isReact18 ? 1 : 2) ).toBe(strictNextHead ? 1 : 2)
expect( expect(
Number(await browser.eval('window.__test_defer_executions')) Number(await browser.eval('window.__test_defer_executions'))
).toBe(strictNextHead || isReact18 ? 1 : 2) ).toBe(strictNextHead ? 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 || isReact18 ? 1 : 2) ).toBe(strictNextHead ? 1 : 2)
expect( expect(
Number(await browser.eval('window.__test_defer_executions')) Number(await browser.eval('window.__test_defer_executions'))
).toBe(strictNextHead || isReact18 ? 1 : 2) ).toBe(strictNextHead ? 1 : 2)
} finally { } finally {
if (browser) { if (browser) {
await browser.close() await browser.close()
......
...@@ -609,11 +609,7 @@ describe.each([[false], [true]])( ...@@ -609,11 +609,7 @@ describe.each([[false], [true]])(
const documentHeadElement = const documentHeadElement =
'<meta name="keywords" content="document head test"/>' '<meta name="keywords" content="document head test"/>'
// charset is not actually at the top. expect(html).toContain(`<head>${nextHeadElement}${documentHeadElement}`)
// data-next-hide-fouc comes first
expect(html).toContain(
`</style></noscript>${nextHeadElement}${documentHeadElement}`
)
}) })
} }
) )
...@@ -486,7 +486,8 @@ describe('app dir - rsc basics', () => { ...@@ -486,7 +486,8 @@ 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-'
it('should not use bundled react for pages with app', async () => { // TODO: (React 19) During Beta, bundled and installed version match.
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)
...@@ -506,6 +507,7 @@ describe('app dir - rsc basics', () => { ...@@ -506,6 +507,7 @@ 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) =>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
}, },
"dependencies": { "dependencies": {
"next": "canary", "next": "canary",
"react": "^18.2.0", "react": "19.0.0-rc-7771d3a7-20240827",
"react-dom": "^18.2.0" "react-dom": "19.0.0-rc-7771d3a7-20240827"
} }
} }
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
}, },
"dependencies": { "dependencies": {
"next": "canary", "next": "canary",
"react": "^18.2.0", "react": "19.0.0-rc-7771d3a7-20240827",
"react-dom": "^18.2.0" "react-dom": "19.0.0-rc-7771d3a7-20240827"
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^18", "@types/react": "^18",
......
...@@ -3,8 +3,6 @@ import { createNext, FileRef } from 'e2e-utils' ...@@ -3,8 +3,6 @@ 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 = true
describe('prerender native module', () => { describe('prerender native module', () => {
let next: NextInstance let next: NextInstance
...@@ -72,9 +70,7 @@ describe('prerender native module', () => { ...@@ -72,9 +70,7 @@ 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/,
isReact18 /node_modules\/react\/cjs\/react\.production\.js/,
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
], ],
notTests: [], notTests: [],
}, },
...@@ -84,9 +80,7 @@ describe('prerender native module', () => { ...@@ -84,9 +80,7 @@ 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/,
isReact18 /node_modules\/react\/cjs\/react\.production\.js/,
? /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,8 +19,6 @@ import { ...@@ -19,8 +19,6 @@ import {
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
const isReact18 = true
describe('Prerender', () => { describe('Prerender', () => {
let next: NextInstance let next: NextInstance
...@@ -2064,9 +2062,7 @@ describe('Prerender', () => { ...@@ -2064,9 +2062,7 @@ 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/,
isReact18 /node_modules\/react\/cjs\/react\.production\.js/,
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
], ],
notTests: [], notTests: [],
}, },
...@@ -2077,9 +2073,7 @@ describe('Prerender', () => { ...@@ -2077,9 +2073,7 @@ 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/,
isReact18 /node_modules\/react\/cjs\/react\.production\.js/,
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
/\/world.txt/, /\/world.txt/,
], ],
notTests: [ notTests: [
...@@ -2094,9 +2088,7 @@ describe('Prerender', () => { ...@@ -2094,9 +2088,7 @@ 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/,
isReact18 /node_modules\/react\/cjs\/react\.production\.js/,
? /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/],
...@@ -2117,7 +2109,7 @@ describe('Prerender', () => { ...@@ -2117,7 +2109,7 @@ describe('Prerender', () => {
) )
) )
} catch (error) { } catch (error) {
error.message += `\n\nPage: ${check.page}\nFiles:\n${files.join('\n')}` error.message += `\n\nFiles:\n${files.join('\n')}`
throw error throw error
} }
......
...@@ -30,6 +30,10 @@ describe('AMP Usage', () => { ...@@ -30,6 +30,10 @@ describe('AMP Usage', () => {
let output = '' let output = ''
beforeAll(async () => { beforeAll(async () => {
await rename(
join(appDir, 'pages/custom-scripts.js'),
join(appDir, 'pages/custom-scripts.js.bak')
)
await rename( await rename(
join(appDir, 'pages/invalid-amp.js'), join(appDir, 'pages/invalid-amp.js'),
join(appDir, 'pages/invalid-amp.js.bak') join(appDir, 'pages/invalid-amp.js.bak')
...@@ -45,6 +49,10 @@ describe('AMP Usage', () => { ...@@ -45,6 +49,10 @@ describe('AMP Usage', () => {
app = await nextStart(appDir, context.appPort) app = await nextStart(appDir, context.appPort)
}) })
afterAll(async () => { afterAll(async () => {
await rename(
join(appDir, 'pages/custom-scripts.js.bak'),
join(appDir, 'pages/custom-scripts.js')
)
await rename( await rename(
join(appDir, 'pages/invalid-amp.js.bak'), join(appDir, 'pages/invalid-amp.js.bak'),
join(appDir, 'pages/invalid-amp.js') join(appDir, 'pages/invalid-amp.js')
...@@ -557,6 +565,25 @@ describe('AMP Usage', () => { ...@@ -557,6 +565,25 @@ describe('AMP Usage', () => {
expect(inspectPayload).toContain('error') expect(inspectPayload).toContain('error')
}) })
it('should detect amp validator warning on custom scripts', async () => {
let inspectPayload = ''
dynamicAppPort = await findPort()
ampDynamic = await launchApp(join(__dirname, '../'), dynamicAppPort, {
onStdout(msg) {
inspectPayload += msg
},
onStderr(msg) {
inspectPayload += msg
},
})
await renderViaHTTP(dynamicAppPort, '/custom-scripts')
await killApp(ampDynamic)
expect(inspectPayload).toContain('error')
})
// eslint-disable-next-line jest/no-identical-title // eslint-disable-next-line jest/no-identical-title
it('should not contain missing files warning', async () => { it('should not contain missing files warning', async () => {
expect(output).toContain('Compiled /only-amp') expect(output).toContain('Compiled /only-amp')
......
...@@ -15,8 +15,6 @@ const appDir = path.join(__dirname, '..') ...@@ -15,8 +15,6 @@ const appDir = path.join(__dirname, '..')
let appPort let appPort
let app let app
const isReact18 = true
const runTests = () => { const runTests = () => {
it('Supports commonjs 1', async () => { it('Supports commonjs 1', async () => {
const browser = await webdriver(appPort, '/commonjs1') const browser = await webdriver(appPort, '/commonjs1')
...@@ -101,19 +99,7 @@ describe('Auto Export', () => { ...@@ -101,19 +99,7 @@ describe('Auto Export', () => {
expect.arrayContaining([ expect.arrayContaining([
{ {
message: expect.stringContaining( message: expect.stringContaining(
'See more info here: https://nextjs.org/docs/messages/react-hydration-error' 'https://react.dev/link/hydration-mismatch'
),
source: 'error',
},
])
)
expect(logs).toEqual(
expect.arrayContaining([
{
message: expect.stringContaining(
isReact18
? 'https://nextjs.org/docs/messages/react-hydration-error'
: 'https://react.dev/link/hydration-mismatch'
), ),
source: 'error', source: 'error',
}, },
......
export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
import React from 'react' import React from 'react'
function CustomComponent() { async function CustomComponent() {
return ( return (
<div> <div>
<h1>the content of a dynamic component</h1> <h1>the content of a dynamic component</h1>
......
...@@ -1180,7 +1180,7 @@ function runTests(mode) { ...@@ -1180,7 +1180,7 @@ function runTests(mode) {
expect(warnings).toEqual([]) expect(warnings).toEqual([])
expect(await browser.elementById('img').getAttribute('src')).toBe('') expect(await browser.elementById('img').getAttribute('src')).toBe(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 +1195,7 @@ function runTests(mode) { ...@@ -1195,7 +1195,7 @@ function runTests(mode) {
) )
expect(warnings).toEqual([]) expect(warnings).toEqual([])
expect(await browser.elementById('img').getAttribute('src')).toBe('') expect(await browser.elementById('img').getAttribute('src')).toBe(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(
......
...@@ -32,7 +32,7 @@ describe('Basics', () => { ...@@ -32,7 +32,7 @@ describe('Basics', () => {
const browser = await webdriver(context.appPort, '/') const browser = await webdriver(context.appPort, '/')
expect(await browser.eval('window.didHydrate')).toBe(true) expect(await browser.eval('window.didHydrate')).toBe(true)
expect(await browser.elementById('react-dom-version').text()).toMatch( expect(await browser.elementById('react-dom-version').text()).toMatch(
/18/ /19/
) )
}) })
......
...@@ -49,10 +49,9 @@ type OmitFirstArgument<F> = F extends ( ...@@ -49,10 +49,9 @@ type OmitFirstArgument<F> = F extends (
? (...args: P) => R ? (...args: P) => R
: never : never
// TODO: Base this off of test matrix
// Do not rename or format. sync-react script relies on this line. // Do not rename or format. sync-react script relies on this line.
// prettier-ignore // prettier-ignore
const nextjsReactPeerVersion = "^18.2.0"; const nextjsReactPeerVersion = "19.0.0-rc-7771d3a7-20240827";
export class NextInstance { export class NextInstance {
protected files: FileRef | { [filename: string]: string | FileRef } protected files: FileRef | { [filename: string]: string | FileRef }
......
...@@ -28,7 +28,7 @@ describe('custom server', () => { ...@@ -28,7 +28,7 @@ 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`)
expect($('body').text()).toMatch(/pages: 18\.\d+\.\d+\{/) expect($('body').text()).toMatch(/pages: 19.0.0/)
}) })
}) })
}) })
......
...@@ -29,8 +29,6 @@ if (process.env.TEST_WASM) { ...@@ -29,8 +29,6 @@ if (process.env.TEST_WASM) {
jest.setTimeout(120 * 1000) jest.setTimeout(120 * 1000)
} }
const isReact18 = true
describe('Production Usage', () => { describe('Production Usage', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: path.join(__dirname, '../fixture'), files: path.join(__dirname, '../fixture'),
...@@ -183,9 +181,7 @@ describe('Production Usage', () => { ...@@ -183,9 +181,7 @@ 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/,
isReact18 /node_modules\/react\/cjs\/react\.production\.js/,
? /node_modules\/react\/cjs\/react\.production\.min\.js/
: /node_modules\/react\/cjs\/react\.production\.js/,
], ],
notTests: [/\0/, /\?/, /!/], notTests: [/\0/, /\?/, /!/],
}, },
...@@ -196,9 +192,7 @@ describe('Production Usage', () => { ...@@ -196,9 +192,7 @@ 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/,
isReact18 /node_modules\/react\/cjs\/react\.production\.js/,
? /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/, /\?/, /!/],
...@@ -210,9 +204,7 @@ describe('Production Usage', () => { ...@@ -210,9 +204,7 @@ 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/,
isReact18 /node_modules\/react\/cjs\/react\.production\.js/,
? /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/,
...@@ -227,9 +219,7 @@ describe('Production Usage', () => { ...@@ -227,9 +219,7 @@ 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/,
isReact18 /node_modules\/react\/cjs\/react\.production\.js/,
? /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