Skip to content

Commit

Permalink
Revert "Disable using prebundled of react for appDir (vercel#41635)"
Browse files Browse the repository at this point in the history
This reverts commit 3a87e81.
  • Loading branch information
timneutkens committed Oct 23, 2022
1 parent f9f6259 commit a0352f6
Show file tree
Hide file tree
Showing 81 changed files with 131,326 additions and 167 deletions.
4 changes: 0 additions & 4 deletions package.json
Expand Up @@ -39,7 +39,6 @@
"lint-staged": "lint-staged",
"next-with-deps": "./scripts/next-with-deps.sh",
"next": "node --trace-deprecation --enable-source-maps packages/next/dist/bin/next",
"next-react-exp": "__NEXT_REACT_CHANNEL=exp node --trace-deprecation --enable-source-maps -r ./test/lib/react-channel-require-hook.js packages/next/dist/bin/next",
"next-no-sourcemaps": "node --trace-deprecation packages/next/dist/bin/next",
"clean-trace-jaeger": "rm -rf test/integration/basic/.next && TRACE_TARGET=JAEGER node --trace-deprecation --enable-source-maps packages/next/dist/bin/next build test/integration/basic",
"debug": "node --inspect packages/next/dist/bin/next",
Expand Down Expand Up @@ -181,9 +180,6 @@
"react-17": "npm:react@17.0.2",
"react-dom": "18.2.0",
"react-dom-17": "npm:react-dom@17.0.2",
"react-exp": "npm:react@0.0.0-experimental-9cdf8a99e-20221018",
"react-dom-exp": "npm:react-dom@0.0.0-experimental-9cdf8a99e-20221018",
"react-server-dom-webpack": "0.0.0-experimental-9cdf8a99e-20221018",
"react-ssr-prepass": "1.0.8",
"react-virtualized": "9.22.3",
"relay-compiler": "13.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/index.ts
Expand Up @@ -303,7 +303,7 @@ export default async function build(
const publicDir = path.join(dir, 'public')
const isAppDirEnabled = !!config.experimental.appDir
if (isAppDirEnabled) {
process.env.NEXT_PREBUNDLED_REACT = '1'
process.env.HAS_APP_DIR = '1'
}
const { pagesDir, appDir } = findPagesDir(dir, isAppDirEnabled)

Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/utils.ts
Expand Up @@ -54,7 +54,7 @@ import {
} from './webpack/require-hook'

loadRequireHook()
if (process.env.NEXT_PREBUNDLED_REACT) {
if (process.env.HAS_APP_DIR) {
overrideBuiltInReactPackages()
}

Expand Down
153 changes: 65 additions & 88 deletions packages/next/build/webpack-config.ts
Expand Up @@ -832,9 +832,6 @@ export default async function getBaseWebpackConfig(
[COMPILER_NAMES.edgeServer]: ['browser', 'module', 'main'],
}

const reactDir = path.dirname(require.resolve('react/package.json'))
const reactDomDir = path.dirname(require.resolve('react-dom/package.json'))

const resolveConfig = {
// Disable .mjs for node_modules bundling
extensions: isNodeServer
Expand Down Expand Up @@ -873,25 +870,19 @@ export default async function getBaseWebpackConfig(

next: NEXT_PROJECT_ROOT,

// Disable until pre-bundling is landed
// ...(hasServerComponents
// ? {
// // 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/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',
// }
// : undefined),
react: reactDir,
'react-dom$': reactDomDir,
'react-dom/server$': `${reactDomDir}/server`,
'react-dom/server.browser$': `${reactDomDir}/server.browser`,
'react-dom/client$': `${reactDomDir}/client`,
...(hasServerComponents
? {
// 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/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',
}
: undefined),

'styled-jsx/style$': require.resolve(`styled-jsx/style`),
'styled-jsx$': require.resolve(`styled-jsx`),
Expand Down Expand Up @@ -1192,7 +1183,12 @@ export default async function getBaseWebpackConfig(
if (layer === WEBPACK_LAYERS.server) {
// All packages should be bundled for the server layer if they're not opted out.
// This option takes priority over the transpilePackages option.
if (isResourceInPackages(res, optoutBundlingPackages)) {
if (
isResourceInPackages(
res,
config.experimental.serverComponentsExternalPackages
)
) {
return `${externalType} ${request}`
}

Expand Down Expand Up @@ -1545,46 +1541,6 @@ export default async function getBaseWebpackConfig(
},
module: {
rules: [
...(hasAppDir && !isClient && !isEdgeServer
? [
{
issuerLayer: WEBPACK_LAYERS.server,
test: (req: string) => {
// If it's not a source code file, or has been opted out of
// bundling, don't resolve it.
if (
!codeCondition.test.test(req) ||
isResourceInPackages(
req,
config.experimental.serverComponentsExternalPackages
)
) {
return false
}

return true
},
resolve: process.env.__NEXT_REACT_CHANNEL
? {
conditionNames: ['react-server', 'node', 'require'],
alias: {
react: `react-${process.env.__NEXT_REACT_CHANNEL}`,
'react-dom': `react-dom-${process.env.__NEXT_REACT_CHANNEL}`,
},
}
: {
conditionNames: ['react-server', 'node', 'require'],
alias: {
// 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: 'react',
'react-dom': 'react-dom',
},
},
},
]
: []),
// TODO: FIXME: do NOT webpack 5 support with this
// x-ref: https://github.com/webpack/webpack/issues/11467
...(!config.experimental.fullySpecified
Expand All @@ -1608,7 +1564,35 @@ export default async function getBaseWebpackConfig(
},
]
: []),
...(hasAppDir && !isClient
? [
{
issuerLayer: WEBPACK_LAYERS.server,
test: (req: string) => {
// If it's not a source code file, or has been opted out of
// bundling, don't resolve it.
if (
!codeCondition.test.test(req) ||
isResourceInPackages(req, optoutBundlingPackages)
) {
return false
}

return true
},
resolve: {
conditionNames: ['react-server', 'node', 'require'],
alias: {
// 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: 'react',
'react-dom': 'react-dom',
},
},
},
]
: []),
...(hasServerComponents && !isClient
? [
// RSC server compilation loaders
Expand Down Expand Up @@ -1645,7 +1629,6 @@ export default async function getBaseWebpackConfig(
// Alias react-dom for ReactDOM.preload usage.
// Alias react for switching between default set and share subset.
oneOf: [
/*
{
// test: codeCondition.test,
issuerLayer: WEBPACK_LAYERS.server,
Expand All @@ -1664,34 +1647,28 @@ export default async function getBaseWebpackConfig(
resolve: {
// It needs `conditionNames` here to require the proper asset,
// when react is acting as dependency of compiled/react-dom.
conditionNames: ['react-server', 'node', 'require'],
alias: {
react: 'react',
'react-dom': 'react-dom',
// Disable before prebundling is landed
// 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/server-rendering-stub',
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/server-rendering-stub',
},
},
},
{
test: codeCondition.test,
resolve: {
alias: {
react: 'next/dist/compiled/react',
'react-dom$': isClient
? 'next/dist/compiled/react-dom/index'
: 'next/dist/compiled/react-dom/server-rendering-stub',
'react-dom/client$':
'next/dist/compiled/react-dom/client',
},
},
},
*/
// Disable before prebundling is landed
// {
// test: codeCondition.test,
// resolve: {
// alias: {
// react: 'next/dist/compiled/react',
// 'react-dom$': isClient
// ? 'next/dist/compiled/react-dom/index'
// : 'next/dist/compiled/react-dom/server-rendering-stub',
// 'react-dom/client$':
// 'next/dist/compiled/react-dom/client',
// },
// },
// },
],
},
]
Expand Down
2 changes: 0 additions & 2 deletions packages/next/build/webpack/require-hook.ts
Expand Up @@ -45,7 +45,6 @@ export function loadRequireHook(aliases: [string, string][] = []) {
}

export function overrideBuiltInReactPackages() {
/*
setRequireOverrides([
['react', require.resolve('next/dist/compiled/react')],
[
Expand Down Expand Up @@ -73,5 +72,4 @@ export function overrideBuiltInReactPackages() {
require.resolve('next/dist/compiled/react-dom/server.browser'),
],
])
*/
}
21 changes: 21 additions & 0 deletions packages/next/compiled/react-dom/LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Meta Platforms, Inc. and affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

0 comments on commit a0352f6

Please sign in to comment.