Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Vendor react@experimental under an experimentalReact flag" #48038

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 3 additions & 7 deletions package.json
Expand Up @@ -197,13 +197,11 @@
"random-seed": "0.3.0",
"react": "18.2.0",
"react-17": "npm:react@17.0.2",
"react-builtin": "npm:react@18.3.0-next-b14f8da15-20230403",
"react-experimental-builtin": "npm:react@0.0.0-experimental-b14f8da15-20230403",
"react-builtin": "npm:react@18.3.0-next-85de6fde5-20230328",
"react-dom": "18.2.0",
"react-dom-17": "npm:react-dom@17.0.2",
"react-dom-builtin": "npm:react-dom@18.3.0-next-b14f8da15-20230403",
"react-dom-experimental-builtin": "npm:react-dom@0.0.0-experimental-b14f8da15-20230403",
"react-server-dom-webpack": "18.3.0-next-b14f8da15-20230403",
"react-dom-builtin": "npm:react-dom@18.3.0-next-85de6fde5-20230328",
"react-server-dom-webpack": "18.3.0-next-85de6fde5-20230328",
"react-ssr-prepass": "1.0.8",
"react-virtualized": "9.22.3",
"relay-compiler": "13.0.2",
Expand All @@ -214,8 +212,6 @@
"rimraf": "3.0.2",
"sass": "1.54.0",
"satori": "0.4.4",
"scheduler-builtin": "npm:scheduler@0.24.0-next-b14f8da15-20230403",
"scheduler-experimental-builtin": "npm:scheduler@0.0.0-experimental-b14f8da15-20230403",
"seedrandom": "3.0.5",
"selenium-webdriver": "4.0.0-beta.4",
"semver": "7.3.7",
Expand Down
5 changes: 1 addition & 4 deletions packages/next/src/build/index.ts
Expand Up @@ -280,7 +280,6 @@ export default async function build(

const publicDir = path.join(dir, 'public')
const isAppDirEnabled = !!config.experimental.appDir
const useExperimentalReact = !!config.experimental.experimentalReact
const initialRequireHookFilePath = require.resolve(
'next/dist/server/initialize-require-hook'
)
Expand All @@ -290,9 +289,7 @@ export default async function build(
)

if (isAppDirEnabled) {
process.env.NEXT_PREBUNDLED_REACT = useExperimentalReact
? 'experimental'
: 'next'
process.env.NEXT_PREBUNDLED_REACT = '1'
}
await promises
.writeFile(
Expand Down
51 changes: 22 additions & 29 deletions packages/next/src/build/webpack-config.ts
Expand Up @@ -683,22 +683,15 @@ export default async function getBaseWebpackConfig(

const hasAppDir = !!config.experimental.appDir && !!appDir
const hasServerComponents = hasAppDir
const useExperimentalReact = !!config.experimental.experimentalReact
const disableOptimizedLoading = true
const enableTypedRoutes = !!config.experimental.typedRoutes && hasAppDir
const builtInReactChannel = useExperimentalReact ? '-experimental' : ''

if (isClient) {
if (isEdgeRuntime(config.experimental.runtime)) {
Log.warn(
'You are using `experimental.runtime` which was removed. Check https://nextjs.org/docs/api-routes/edge-api-routes on how to use edge runtime.'
)
}
if (useExperimentalReact && !hasAppDir) {
Log.warn(
'You are using `experimental.experimentalReact` which requires `experimental.appDir` to be enabled.'
)
}
}

const babelConfigFile = await getBabelConfigFile(dir)
Expand Down Expand Up @@ -1032,11 +1025,13 @@ export default async function getBaseWebpackConfig(
? {
// For react and react-dom, alias them dynamically for server layer
// and others in the loaders configuration
'react-dom/client$': `next/dist/compiled/react-dom${builtInReactChannel}/client`,
'react-dom/server$': `next/dist/compiled/react-dom${builtInReactChannel}/server`,
'react-dom/server.browser$': `next/dist/compiled/react-dom${builtInReactChannel}/server.browser`,
'react/jsx-dev-runtime$': `next/dist/compiled/react${builtInReactChannel}/jsx-dev-runtime`,
'react/jsx-runtime$': `next/dist/compiled/react${builtInReactChannel}/jsx-runtime`,
'react-dom/client$': 'next/dist/compiled/react-dom/client',
'react-dom/server$': 'next/dist/compiled/react-dom/server',
'react-dom/server.browser$':
'next/dist/compiled/react-dom/server.browser',
'react/jsx-dev-runtime$':
'next/dist/compiled/react/jsx-dev-runtime',
'react/jsx-runtime$': 'next/dist/compiled/react/jsx-runtime',
}
: {
react: reactDir,
Expand Down Expand Up @@ -1238,17 +1233,11 @@ export default async function getBaseWebpackConfig(

if (/^(react(?:$|\/)|react-dom(?:$|\/))/.test(request)) {
// override react-dom to server-rendering-stub for server
const channel = useExperimentalReact ? '-experimental' : ''
if (
request === 'react-dom' &&
(layer === WEBPACK_LAYERS.client || layer === WEBPACK_LAYERS.server)
) {
request = `react-dom${channel}/server-rendering-stub`
} else {
// `react` -> `react-experimental`
// `react-dom` -> `react-dom-experimental`
// `react/jsx-runtime` -> `react-experimental/jsx-runtime`
request = request.replace(/^(react|react-dom)/, (m) => m + channel)
request = 'react-dom/server-rendering-stub'
}
return `commonjs ${hasAppDir ? 'next/dist/compiled/' : ''}${request}`
}
Expand Down Expand Up @@ -1777,8 +1766,9 @@ export default async function getBaseWebpackConfig(
// If missing the alias override here, the default alias will be used which aliases
// react to the direct file path, not the package name. In that case the condition
// will be ignored completely.
react: `next/dist/compiled/react${builtInReactChannel}/react.shared-subset`,
'react-dom$': `next/dist/compiled/react-dom${builtInReactChannel}/server-rendering-stub`,
react: 'next/dist/compiled/react/react.shared-subset',
'react-dom$':
'next/dist/compiled/react-dom/server-rendering-stub',
},
},
use: {
Expand Down Expand Up @@ -1864,10 +1854,11 @@ export default async function getBaseWebpackConfig(
// It needs `conditionNames` here to require the proper asset,
// when react is acting as dependency of compiled/react-dom.
alias: {
react: `next/dist/compiled/react${builtInReactChannel}/react.shared-subset`,
react: 'next/dist/compiled/react/react.shared-subset',
// Use server rendering stub for RSC
// x-ref: https://github.com/facebook/react/pull/25436
'react-dom$': `next/dist/compiled/react-dom${builtInReactChannel}/server-rendering-stub`,
'react-dom$':
'next/dist/compiled/react-dom/server-rendering-stub',
},
},
},
Expand All @@ -1876,20 +1867,22 @@ export default async function getBaseWebpackConfig(
test: codeCondition.test,
resolve: {
alias: {
react: `next/dist/compiled/react${builtInReactChannel}`,
'react-dom$': `next/dist/compiled/react-dom${builtInReactChannel}/server-rendering-stub`,
react: 'next/dist/compiled/react',
'react-dom$':
'next/dist/compiled/react-dom/server-rendering-stub',
},
},
},
{
test: codeCondition.test,
resolve: {
alias: {
react: `next/dist/compiled/react${builtInReactChannel}`,
react: 'next/dist/compiled/react',
'react-dom$': reactProductionProfiling
? `next/dist/compiled/react-dom${builtInReactChannel}/cjs/react-dom.profiling.min`
: `next/dist/compiled/react-dom${builtInReactChannel}`,
'react-dom/client$': `next/dist/compiled/react-dom${builtInReactChannel}/client`,
? 'next/dist/compiled/react-dom/cjs/react-dom.profiling.min'
: 'next/dist/compiled/react-dom',
'react-dom/client$':
'next/dist/compiled/react-dom/client',
},
},
},
Expand Down
18 changes: 7 additions & 11 deletions packages/next/src/build/webpack/require-hook.ts
Expand Up @@ -48,35 +48,31 @@ export function loadRequireHook(aliases: [string, string][] = []) {
}

export function overrideBuiltInReactPackages() {
const channel =
process.env.NEXT_PREBUNDLED_REACT === 'experimental' ? '-experimental' : ''
setRequireOverrides([
['react', require.resolve(`next/dist/compiled/react${channel}`)],
['react', require.resolve('next/dist/compiled/react')],
[
'react/jsx-runtime',
require.resolve(`next/dist/compiled/react${channel}/jsx-runtime`),
require.resolve('next/dist/compiled/react/jsx-runtime'),
],
[
'react/jsx-dev-runtime',
require.resolve(`next/dist/compiled/react${channel}/jsx-dev-runtime`),
require.resolve('next/dist/compiled/react/jsx-dev-runtime'),
],
[
'react-dom',
require.resolve(
`next/dist/compiled/react-dom${channel}/server-rendering-stub`
),
require.resolve('next/dist/compiled/react-dom/server-rendering-stub'),
],
[
'react-dom/client',
require.resolve(`next/dist/compiled/react-dom${channel}/client`),
require.resolve('next/dist/compiled/react-dom/client'),
],
[
'react-dom/server',
require.resolve(`next/dist/compiled/react-dom${channel}/server`),
require.resolve('next/dist/compiled/react-dom/server'),
],
[
'react-dom/server.browser',
require.resolve(`next/dist/compiled/react-dom${channel}/server.browser`),
require.resolve('next/dist/compiled/react-dom/server.browser'),
],
])
}
21 changes: 0 additions & 21 deletions packages/next/src/compiled/react-dom-experimental/LICENSE

This file was deleted.