Skip to content

Commit

Permalink
fix(next): add alias to new react exports (#65761)
Browse files Browse the repository at this point in the history
### What

There is a new react exports entrypoints in pkg.json, which we didn't
add alias as similar to other export conditions.
  • Loading branch information
kwonoj authored May 14, 2024
1 parent 2fb5ad7 commit 64f38c4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/next-swc/crates/next-core/src/next_import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ async fn rsc_aliases(
"react-dom" => format!("next/dist/compiled/react-dom{react_channel}"),
"react/jsx-runtime" => format!("next/dist/compiled/react{react_channel}/jsx-runtime"),
"react/jsx-dev-runtime" => format!("next/dist/compiled/react{react_channel}/jsx-dev-runtime"),
"react/compiler-runtime" => format!("next/dist/compiled/react{react_channel}/compiler-runtime"),
"react-dom/client" => format!("next/dist/compiled/react-dom{react_channel}/client"),
"react-dom/static" => format!("next/dist/compiled/react-dom-experimental/static"),
"react-dom/static.edge" => format!("next/dist/compiled/react-dom-experimental/static.edge"),
Expand All @@ -687,6 +688,7 @@ async fn rsc_aliases(
alias.extend(indexmap! {
"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"),
"react/compiler-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-compiler-runtime"),
"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"),
"react-server-dom-webpack/client.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-server-dom-turbopack-client-edge"),
Expand All @@ -697,6 +699,7 @@ async fn rsc_aliases(
alias.extend(indexmap! {
"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"),
"react/compiler-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-compiler-runtime"),
"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"),
"react-server-dom-webpack/server.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-edge"),
Expand All @@ -719,8 +722,10 @@ async fn rsc_aliases(
"next/dist/compiled/react" => format!("next/dist/compiled/react{react_channel}/react.react-server"),
"next/dist/compiled/react-experimental" => format!("next/dist/compiled/react-experimental/react.react-server"),
"react/jsx-runtime" => format!("next/dist/compiled/react{react_channel}/jsx-runtime.react-server"),
"react/compiler-runtime" => format!("next/dist/compiled/react{react_channel}/compiler-runtime"),
"next/dist/compiled/react/jsx-runtime" => format!("next/dist/compiled/react{react_channel}/jsx-runtime.react-server"),
"next/dist/compiled/react-experimental/jsx-runtime" => format!("next/dist/compiled/react-experimental/jsx-runtime.react-server"),
"next/dist/compiled/react/compiler-runtime" => format!("next/dist/compiled/react{react_channel}/compiler-runtime"),
"react/jsx-dev-runtime" => format!("next/dist/compiled/react{react_channel}/jsx-dev-runtime.react-server"),
"next/dist/compiled/react/jsx-dev-runtime" => format!("next/dist/compiled/react{react_channel}/jsx-dev-runtime.react-server"),
"next/dist/compiled/react-experimental/jsx-dev-runtime" => format!("next/dist/compiled/react-experimental/jsx-dev-runtime.react-server"),
Expand Down
4 changes: 4 additions & 0 deletions packages/next/src/build/create-compiler-aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export function createRSCAliases(
'react-dom$': `next/dist/compiled/react-dom${bundledReactChannel}`,
'react/jsx-runtime$': `next/dist/compiled/react${bundledReactChannel}/jsx-runtime`,
'react/jsx-dev-runtime$': `next/dist/compiled/react${bundledReactChannel}/jsx-dev-runtime`,
'react/compiler-runtime$': `next/dist/compiled/react${bundledReactChannel}/compiler-runtime`,
'react-dom/client$': `next/dist/compiled/react-dom${bundledReactChannel}/client`,
'react-dom/server$': `next/dist/compiled/react-dom${bundledReactChannel}/server`,
'react-dom/static$': `next/dist/compiled/react-dom-experimental/static`,
Expand All @@ -272,6 +273,7 @@ export function createRSCAliases(
alias = Object.assign(alias, {
'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`,
'react/compiler-runtime$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-compiler-runtime`,
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`,
'react-server-dom-webpack/client.edge$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-server-dom-webpack-client-edge`,
Expand All @@ -280,6 +282,7 @@ export function createRSCAliases(
alias = Object.assign(alias, {
'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`,
'react/compiler-runtime$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-compiler-runtime`,
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`,
'react-server-dom-webpack/server.edge$': `next/dist/server/future/route-modules/app-page/vendored/${layer}/react-server-dom-webpack-server-edge`,
Expand All @@ -295,6 +298,7 @@ export function createRSCAliases(
'next/dist/compiled/react$': `next/dist/compiled/react${bundledReactChannel}/react.react-server`,
'next/dist/compiled/react-experimental$': `next/dist/compiled/react-experimental/react.react-server`,
'react/jsx-runtime$': `next/dist/compiled/react${bundledReactChannel}/jsx-runtime.react-server`,
'react/compiler-runtime$': `next/dist/compiled/react${bundledReactChannel}/compiler-runtime`,
'next/dist/compiled/react/jsx-runtime$': `next/dist/compiled/react${bundledReactChannel}/jsx-runtime.react-server`,
'next/dist/compiled/react-experimental/jsx-runtime$': `next/dist/compiled/react-experimental/jsx-runtime.react-server`,
'react/jsx-dev-runtime$': `next/dist/compiled/react${bundledReactChannel}/jsx-dev-runtime.react-server`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as React from 'react'
import * as ReactDOM from 'react-dom'
import * as ReactJsxDevRuntime from 'react/jsx-dev-runtime'
import * as ReactJsxRuntime from 'react/jsx-runtime'
//@ts-expect-error TODO: current @types/react does not have exported types for this import
import * as ReactCompilerRuntime from 'react/compiler-runtime'
import '../../../../../next-fetch'

function getAltProxyForBindingsDEV(
Expand Down Expand Up @@ -80,6 +82,7 @@ export {
React,
ReactJsxDevRuntime,
ReactJsxRuntime,
ReactCompilerRuntime,
ReactDOM,
ReactServerDOMWebpackServerEdge,
ReactServerDOMTurbopackServerEdge,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = require('../../module.compiled').vendored[
'react-rsc'
].ReactCompilerRuntime
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as React from 'react'
import * as ReactDOM from 'react-dom'
import * as ReactJsxDevRuntime from 'react/jsx-dev-runtime'
import * as ReactJsxRuntime from 'react/jsx-runtime'
//@ts-expect-error TODO: current @types/react does not have exported types for this import
import * as ReactCompilerRuntime from 'react/compiler-runtime'

// eslint-disable-next-line import/no-extraneous-dependencies
import * as ReactDOMServerEdge from 'react-dom/server.edge'
Expand Down Expand Up @@ -54,6 +56,7 @@ export {
React,
ReactJsxDevRuntime,
ReactJsxRuntime,
ReactCompilerRuntime,
ReactDOM,
ReactDOMServerEdge,
ReactServerDOMTurbopackClientEdge,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = require('../../module.compiled').vendored[
'react-ssr'
].ReactCompilerRuntime
4 changes: 4 additions & 0 deletions packages/next/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const pagesExternals = [
'react/package.json',
'react/jsx-runtime',
'react/jsx-dev-runtime',
'react/compiler-runtime',
'react-dom',
'react-dom/package.json',
'react-dom/client',
Expand Down Expand Up @@ -36,6 +37,7 @@ function makeAppAliases(reactChannel = '') {
'react-dom$': `next/dist/compiled/react-dom${reactChannel}`,
'react/jsx-runtime$': `next/dist/compiled/react${reactChannel}/jsx-runtime`,
'react/jsx-dev-runtime$': `next/dist/compiled/react${reactChannel}/jsx-dev-runtime`,
'react/compiler-runtime$': `next/dist/compiled/react${reactChannel}/compiler-runtime`,
'react-dom/client$': `next/dist/compiled/react-dom${reactChannel}/client`,
'react-dom/server$': `next/dist/compiled/react-dom${reactChannel}/server`,
'react-dom/static$': `next/dist/compiled/react-dom-experimental/static`,
Expand Down Expand Up @@ -241,6 +243,8 @@ module.exports = ({ dev, turbo, bundleType, experimental }) => {
[`next/dist/compiled/react${bundledReactChannel}/jsx-runtime$`]: `next/dist/compiled/react${bundledReactChannel}/jsx-runtime.react-server`,
'react/jsx-dev-runtime$': `next/dist/compiled/react${bundledReactChannel}/jsx-dev-runtime.react-server`,
[`next/dist/compiled/react${bundledReactChannel}/jsx-dev-runtime$`]: `next/dist/compiled/react${bundledReactChannel}/jsx-dev-runtime.react-server`,
'react/compiler-runtime$': `next/dist/compiled/react${bundledReactChannel}/compiler-runtime`,
[`next/dist/compiled/react${bundledReactChannel}/compiler-runtime$`]: `next/dist/compiled/react${bundledReactChannel}/compiler-runtime`,
'react-dom$': `next/dist/compiled/react-dom${bundledReactChannel}/react-dom.react-server`,
[`next/dist/compiled/react-dom${bundledReactChannel}$`]: `next/dist/compiled/react-dom${bundledReactChannel}/react-dom.react-server`,
},
Expand Down

0 comments on commit 64f38c4

Please sign in to comment.