Skip to content

Commit

Permalink
Fix aliases in vendored React
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 29, 2024
1 parent 9309571 commit ad1dd0d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
12 changes: 12 additions & 0 deletions packages/next/src/build/create-compiler-aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,24 +297,36 @@ export function createRSCAliases(
alias[
'next/dist/compiled/react$'
] = `next/dist/compiled/react${bundledReactChannel}/react.react-server`
alias[
'next/dist/compiled/react-experimental$'
] = `next/dist/compiled/react-experimental/react.react-server`
alias[
'react/jsx-runtime$'
] = `next/dist/compiled/react${bundledReactChannel}/jsx-runtime.react-server`
alias[
'next/dist/compiled/react/jsx-runtime$'
] = `next/dist/compiled/react${bundledReactChannel}/jsx-runtime.react-server`
alias[
'next/dist/compiled/react-experimental/jsx-runtime$'
] = `next/dist/compiled/react-experimental/jsx-runtime.react-server`
alias[
'react/jsx-dev-runtime$'
] = `next/dist/compiled/react${bundledReactChannel}/jsx-dev-runtime.react-server`
alias[
'next/dist/compiled/react/jsx-dev-runtime$'
] = `next/dist/compiled/react${bundledReactChannel}/jsx-dev-runtime.react-server`
alias[
'next/dist/compiled/react-experimental/jsx-dev-runtime$'
] = `next/dist/compiled/react-experimental/jsx-dev-runtime.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`
alias[
'next/dist/compiled/react-dom-experimental$'
] = `next/dist/compiled/react-dom-experimental/react-dom.react-server`
}
}

Expand Down
45 changes: 29 additions & 16 deletions packages/next/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const webpack = require('webpack')
const path = require('path')
const TerserPlugin = require('terser-webpack-plugin')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const { writeFileSync } = require('fs')
const StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin

const pagesExternals = [
'react',
Expand Down Expand Up @@ -211,6 +213,25 @@ module.exports = ({ dev, turbo, bundleType, experimental }) => {
}
: {}),
}),
new StatsWriterPlugin({
stats: 'verbose',
transform(data) {
const json = JSON.stringify(data, null, 2)

writeFileSync(
path.join(
process.env.HOME,
'stats/server-future',
`stats.bad.${bundleType}${
experimental ? '.experimental' : ''
}.json`
),
json
)

return json
},
}),
].filter(Boolean),
stats: {
optimizationBailout: true,
Expand All @@ -236,13 +257,13 @@ module.exports = ({ dev, turbo, bundleType, experimental }) => {
conditionNames: ['react-server', '...'],
alias: {
react$: `next/dist/compiled/react${bundledReactChannel}/react.react-server`,
'next/dist/compiled/react$': `next/dist/compiled/react${bundledReactChannel}/react.react-server`,
[`next/dist/compiled/react${bundledReactChannel}$`]: `next/dist/compiled/react${bundledReactChannel}/react.react-server`,
'react/jsx-runtime$': `next/dist/compiled/react${bundledReactChannel}/jsx-runtime.react-server`,
'next/dist/compiled/react/jsx-runtime$': `next/dist/compiled/react${bundledReactChannel}/jsx-runtime.react-server`,
[`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/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-dom$': `next/dist/compiled/react-dom${bundledReactChannel}/react-dom.react-server`,
'next/dist/compiled/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`,
},
},
layer: 'react-server',
Expand All @@ -252,18 +273,10 @@ module.exports = ({ dev, turbo, bundleType, experimental }) => {
resolve: {
conditionNames: ['react-server', '...'],
alias: {
react$: `next/dist/compiled/react${
experimental ? '-experimental' : ''
}/react.react-server`,
'next/dist/compiled/react$': `next/dist/compiled/react${
experimental ? '-experimental' : ''
}/react.react-server`,
'react-dom$': `next/dist/compiled/react-dom${
experimental ? '-experimental' : ''
}/react-dom.react-server`,
'next/dist/compiled/react-dom$': `next/dist/compiled/react-dom${
experimental ? '-experimental' : ''
}/react-dom.react-server`,
react$: `next/dist/compiled/react${bundledReactChannel}/react.react-server`,
[`next/dist/compiled/react${bundledReactChannel}$`]: `next/dist/compiled/react${bundledReactChannel}/react.react-server`,
'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 ad1dd0d

Please sign in to comment.