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

Use consistent import of vendored React within vendored React #64806

Draft
wants to merge 16 commits into
base: canary
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/next-swc/crates/next-core/src/next_import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,27 +700,39 @@ async fn rsc_aliases(
ServerContextType::AppSSR { .. } => {
alias.extend(indexmap! {
"react/jsx-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-jsx-runtime"),
"next/dist/compiled/react/jsx-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-jsx-runtime"),
"react/jsx-dev-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-jsx-dev-runtime"),
"next/dist/compiled/react/jsx-dev-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-jsx-dev-runtime"),
"react" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react"),
"next/dist/compiled/react" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react"),
"react-dom" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-dom"),
"next/dist/compiled/react-dom" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-dom"),
"react-server-dom-webpack/client.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-server-dom-turbopack-client-edge"),
"next/dist/compiled/react-server-dom-webpack/client.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-server-dom-turbopack-client-edge"),
"react-server-dom-turbopack/client.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-server-dom-turbopack-client-edge"),
"next/dist/compiled/react-server-dom-turbopack/client.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-server-dom-turbopack-client-edge"),
})
}
ServerContextType::AppRSC { .. } | ServerContextType::AppRoute { .. } => {
alias.extend(indexmap! {
"react/jsx-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-jsx-runtime"),
"next/dist/compiled/react/jsx-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-jsx-runtime"),
"react/jsx-dev-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-jsx-dev-runtime"),
"next/dist/compiled/react/jsx-dev-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-jsx-dev-runtime"),
"react" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react"),
"next/dist/compiled/react" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react"),
"react-dom" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-dom"),
"next/dist/compiled/react-dom" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-dom"),
"react-server-dom-webpack/server.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-edge"),
"next/dist/compiled/react-server-dom-webpack/server.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-edge"),
"react-server-dom-webpack/server.node" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-node"),
"next/dist/compiled/react-server-dom-webpack/server.node" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-node"),
"react-server-dom-turbopack/server.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-edge"),
"next/dist/compiled/react-server-dom-turbopack/server.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-edge"),
"react-server-dom-turbopack/server.node" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-node"),
"next/dist/compiled/react-server-dom-turbopack/server.node" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-node"),
"next/navigation" => format!("next/dist/api/navigation.react-server"),

// Needed to make `react-dom/server` work.
"next/dist/compiled/react" => format!("next/dist/compiled/react/index.js"),
})
}
_ => {}
Expand Down
25 changes: 23 additions & 2 deletions packages/next/src/build/create-compiler-aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ export function createWebpackAliases({
}
: undefined),

next: NEXT_PROJECT_ROOT,

'styled-jsx/style$': defaultOverrides['styled-jsx/style'],
'styled-jsx$': defaultOverrides['styled-jsx'],

Expand Down Expand Up @@ -273,19 +271,30 @@ export function createRSCAliases(
if (layer === WEBPACK_LAYERS.serverSideRendering) {
alias = Object.assign(alias, {
'react/jsx-runtime$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-jsx-runtime`,
'next/dist/compiled/react/jsx-runtime$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-jsx-runtime`,
'react/jsx-dev-runtime$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-jsx-dev-runtime`,
'next/dist/compiled/react/jsx-dev-runtime$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-jsx-dev-runtime`,
react$: `next/dist/server/future/route-modules/app-page/vendored/${layer}/react`,
'next/dist/compiled/react$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react`,
'react-dom$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-dom`,
'next/dist/compiled/react-dom$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-dom`,
'react-server-dom-webpack/client.edge$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-server-dom-webpack-client-edge`,
'next/dist/compiled/react-server-dom-webpack/client.edge$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-server-dom-webpack-client-edge`,
})
} else if (layer === WEBPACK_LAYERS.reactServerComponents) {
alias = Object.assign(alias, {
'react/jsx-runtime$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-jsx-runtime`,
'next/dist/compiled/react/jsx-runtime$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-jsx-runtime`,
'react/jsx-dev-runtime$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-jsx-dev-runtime`,
'next/dist/compiled/react/jsx-dev-runtime$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-jsx-dev-runtime`,
react$: `next/dist/server/future/route-modules/app-page/vendored/${layer}/react`,
'next/dist/compiled/react$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react`,
'react-dom$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-dom`,
'next/dist/compiled/react-dom$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-dom`,
'react-server-dom-webpack/server.edge$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-server-dom-webpack-server-edge`,
'next/dist/compiled/react-server-dom-webpack/server.edge$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-server-dom-webpack-server-edge`,
'react-server-dom-webpack/server.node$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-server-dom-webpack-server-node`,
'next/dist/compiled/react-server-dom-webpack/server.node$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-server-dom-webpack-server-node`,
})
}
}
Expand All @@ -295,21 +304,33 @@ export function createRSCAliases(
alias[
'react$'
] = `next/dist/compiled/react${bundledReactChannel}/react.react-server`
alias[
'next/dist/compiled/react$'
] = `next/dist/compiled/react${bundledReactChannel}/react.react-server`
alias[
'react-dom$'
] = `next/dist/compiled/react-dom${bundledReactChannel}/react-dom.react-server`
alias[
'next/dist/compiled/react-dom$'
] = `next/dist/compiled/react-dom${bundledReactChannel}/react-dom.react-server`
} else {
// x-ref: https://github.com/facebook/react/pull/25436
alias[
'react-dom$'
] = `next/dist/compiled/react-dom${bundledReactChannel}/server-rendering-stub`
alias[
'next/dist/compiled/react-dom$'
] = `next/dist/compiled/react-dom${bundledReactChannel}/server-rendering-stub`
}
}

if (reactProductionProfiling) {
alias[
'react-dom$'
] = `next/dist/compiled/react-dom${bundledReactChannel}/profiling`
alias[
'next/dist/compiled/react-dom$'
] = `next/dist/compiled/react-dom${bundledReactChannel}/profiling`
}

alias[
Expand Down
7 changes: 7 additions & 0 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,13 @@ export default async function getBaseWebpackConfig(
]
},
},
{
resolve: {
alias: {
next: NEXT_PROJECT_ROOT,
},
},
},
],
},
plugins: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (process.env.NODE_ENV !== "production") {
'use strict';

var React = require("next/dist/compiled/react-experimental");
var ReactDOM = require('react-dom');
var ReactDOM = require("next/dist/compiled/react-dom-experimental");

var ReactVersion = '18.3.0-experimental-c3048aab4-20240326';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

var React = require("next/dist/compiled/react-experimental");
var ReactDOM = require('react-dom');
var ReactDOM = require("next/dist/compiled/react-dom-experimental");

// Do not require this module directly! Use normal `invariant` calls with
// template literal strings. The messages will be replaced with error codes
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (process.env.NODE_ENV !== "production") {
'use strict';

var React = require("next/dist/compiled/react-experimental");
var ReactDOM = require('react-dom');
var ReactDOM = require("next/dist/compiled/react-dom-experimental");
var stream = require('stream');

var ReactVersion = '18.3.0-experimental-c3048aab4-20240326';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

var React = require("next/dist/compiled/react-experimental");
var ReactDOM = require('react-dom');
var ReactDOM = require("next/dist/compiled/react-dom-experimental");
var stream = require('stream');

var ReactVersion = '18.3.0-experimental-c3048aab4-20240326';
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (process.env.NODE_ENV !== "production") {
'use strict';

var React = require("next/dist/compiled/react-experimental");
var ReactDOM = require('react-dom');
var ReactDOM = require("next/dist/compiled/react-dom-experimental");

var ReactVersion = '18.3.0-experimental-c3048aab4-20240326';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

var React = require("next/dist/compiled/react-experimental");
var ReactDOM = require('react-dom');
var ReactDOM = require("next/dist/compiled/react-dom-experimental");

var ReactVersion = '18.3.0-experimental-c3048aab4-20240326';

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

var React = require("next/dist/compiled/react-experimental");
var ReactDOM = require('react-dom');
var ReactDOM = require("next/dist/compiled/react-dom-experimental");

var ReactVersion = '18.3.0-experimental-c3048aab4-20240326';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (process.env.NODE_ENV !== "production") {
'use strict';

var React = require("next/dist/compiled/react-experimental");
var ReactDOM = require('react-dom');
var ReactDOM = require("next/dist/compiled/react-dom-experimental");

var ReactVersion = '18.3.0-experimental-c3048aab4-20240326';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

var React = require("next/dist/compiled/react-experimental");
var ReactDOM = require('react-dom');
var ReactDOM = require("next/dist/compiled/react-dom-experimental");

var ReactVersion = '18.3.0-experimental-c3048aab4-20240326';

Expand Down
Loading
Loading