Unverified Commit 8e8a86ee authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Add alias for react-dom react-server condition (#63588)

`react-dom` also contains a `react-server` condition that need to be
picked up in RSC bundle layer, like what we did for react. This will
ensures the server runtime smaller and you don't accidentally use the
client apis on server side.


Closes NEXT-2898

---------
Co-authored-by: 's avatarJanka Uryga <lolzatu2@gmail.com>
parent 142b48f3
...@@ -296,6 +296,9 @@ export function createRSCAliases( ...@@ -296,6 +296,9 @@ export function createRSCAliases(
alias[ alias[
'react$' 'react$'
] = `next/dist/compiled/react${bundledReactChannel}/react.react-server` ] = `next/dist/compiled/react${bundledReactChannel}/react.react-server`
alias[
'react-dom$'
] = `next/dist/compiled/react-dom${bundledReactChannel}/react-dom.react-server`
} }
// Use server rendering stub for RSC and SSR // Use server rendering stub for RSC and SSR
// x-ref: https://github.com/facebook/react/pull/25436 // x-ref: https://github.com/facebook/react/pull/25436
......
import * as React from 'react' import * as React from 'react'
import * as ReactDOM from 'react-dom/server-rendering-stub' import * as ReactDOM from 'react-dom'
import * as ReactJsxDevRuntime from 'react/jsx-dev-runtime' import * as ReactJsxDevRuntime from 'react/jsx-dev-runtime'
import * as ReactJsxRuntime from 'react/jsx-runtime' import * as ReactJsxRuntime from 'react/jsx-runtime'
...@@ -67,6 +67,14 @@ if (process.env.TURBOPACK) { ...@@ -67,6 +67,14 @@ if (process.env.TURBOPACK) {
} }
} }
if (ReactDOM.version === undefined) {
// FIXME: ReactDOM's 'react-server' entrypoint is missing `.version`,
// which makes our tests fail when it's used, so this is an ugly workaround
// (but should be safe because these are always kept in sync anyway)
// @ts-expect-error
ReactDOM.version = React.version
}
export { export {
React, React,
ReactJsxDevRuntime, ReactJsxDevRuntime,
......
...@@ -238,6 +238,12 @@ module.exports = ({ dev, turbo, bundleType, experimental }) => { ...@@ -238,6 +238,12 @@ module.exports = ({ dev, turbo, bundleType, experimental }) => {
'next/dist/compiled/react$': `next/dist/compiled/react${ 'next/dist/compiled/react$': `next/dist/compiled/react${
experimental ? '-experimental' : '' experimental ? '-experimental' : ''
}/react.react-server`, }/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`,
}, },
}, },
layer: 'react-server', layer: 'react-server',
...@@ -253,6 +259,12 @@ module.exports = ({ dev, turbo, bundleType, experimental }) => { ...@@ -253,6 +259,12 @@ module.exports = ({ dev, turbo, bundleType, experimental }) => {
'next/dist/compiled/react$': `next/dist/compiled/react${ 'next/dist/compiled/react$': `next/dist/compiled/react${
experimental ? '-experimental' : '' experimental ? '-experimental' : ''
}/react.react-server`, }/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`,
}, },
}, },
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment