From 299b3650f5e122cf48a8b4a701ce484f96c872b3 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Fri, 16 Aug 2024 21:45:06 +0200 Subject: [PATCH] Remove redundant react-dom/server.browser shim --- .../next/src/build/create-compiler-aliases.ts | 3 +- .../react-dom-server-browser-experimental.js | 16 ------- .../webpack/alias/react-dom-server-browser.js | 16 ------- packages/next/types/$$compiled.internal.d.ts | 1 - packages/next/types/react-dom.d.ts | 2 - packages/next/webpack.config.js | 3 -- .../app-dir/ssr-in-rsc/ssr-in-rsc.test.ts | 46 ++----------------- 7 files changed, 4 insertions(+), 83 deletions(-) delete mode 100644 packages/next/src/build/webpack/alias/react-dom-server-browser-experimental.js delete mode 100644 packages/next/src/build/webpack/alias/react-dom-server-browser.js diff --git a/packages/next/src/build/create-compiler-aliases.ts b/packages/next/src/build/create-compiler-aliases.ts index d6f7957fc6627..06f9e77515e89 100644 --- a/packages/next/src/build/create-compiler-aliases.ts +++ b/packages/next/src/build/create-compiler-aliases.ts @@ -269,9 +269,8 @@ export function createRSCAliases( 'react-dom/static$': `next/dist/compiled/react-dom${bundledReactChannel}/static`, 'react-dom/static.edge$': `next/dist/compiled/react-dom${bundledReactChannel}/static.edge`, 'react-dom/static.browser$': `next/dist/compiled/react-dom${bundledReactChannel}/static.browser`, - // optimizations to ignore the legacy build of react-dom/server in `server.browser` build + // optimizations to ignore the legacy build of react-dom/server in `server.edge` build 'react-dom/server.edge$': `next/dist/build/webpack/alias/react-dom-server-edge${bundledReactChannel}.js`, - 'react-dom/server.browser$': `next/dist/build/webpack/alias/react-dom-server-browser${bundledReactChannel}.js`, // react-server-dom-webpack alias ...createRSCRendererAliases(bundledReactChannel), } diff --git a/packages/next/src/build/webpack/alias/react-dom-server-browser-experimental.js b/packages/next/src/build/webpack/alias/react-dom-server-browser-experimental.js deleted file mode 100644 index e76c061adb04f..0000000000000 --- a/packages/next/src/build/webpack/alias/react-dom-server-browser-experimental.js +++ /dev/null @@ -1,16 +0,0 @@ -var l, s -if (process.env.NODE_ENV === 'production') { - l = require('next/dist/compiled/react-dom-experimental/cjs/react-dom-server-legacy.browser.production.js') - s = require('next/dist/compiled/react-dom-experimental/cjs/react-dom-server.browser.production.js') -} else { - l = require('next/dist/compiled/react-dom-experimental/cjs/react-dom-server-legacy.browser.development.js') - s = require('next/dist/compiled/react-dom-experimental/cjs/react-dom-server.browser.development.js') -} - -exports.version = l.version -exports.renderToString = l.renderToString -exports.renderToStaticMarkup = l.renderToStaticMarkup -exports.renderToReadableStream = s.renderToReadableStream -if (s.resume) { - exports.resume = s.resume -} diff --git a/packages/next/src/build/webpack/alias/react-dom-server-browser.js b/packages/next/src/build/webpack/alias/react-dom-server-browser.js deleted file mode 100644 index a331ffab37ea0..0000000000000 --- a/packages/next/src/build/webpack/alias/react-dom-server-browser.js +++ /dev/null @@ -1,16 +0,0 @@ -var l, s -if (process.env.NODE_ENV === 'production') { - l = require('next/dist/compiled/react-dom/cjs/react-dom-server-legacy.browser.production.js') - s = require('next/dist/compiled/react-dom/cjs/react-dom-server.browser.production.js') -} else { - l = require('next/dist/compiled/react-dom/cjs/react-dom-server-legacy.browser.development.js') - s = require('next/dist/compiled/react-dom/cjs/react-dom-server.browser.development.js') -} - -exports.version = l.version -exports.renderToString = l.renderToString -exports.renderToStaticMarkup = l.renderToStaticMarkup -exports.renderToReadableStream = s.renderToReadableStream -if (s.resume) { - exports.resume = s.resume -} diff --git a/packages/next/types/$$compiled.internal.d.ts b/packages/next/types/$$compiled.internal.d.ts index 6455620694174..0fd22be3442d2 100644 --- a/packages/next/types/$$compiled.internal.d.ts +++ b/packages/next/types/$$compiled.internal.d.ts @@ -23,7 +23,6 @@ declare module 'next/dist/compiled/react-server-dom-turbopack/server.edge' declare module 'next/dist/client/app-call-server' declare module 'next/dist/compiled/react-dom/server' declare module 'next/dist/compiled/react-dom/server.edge' -declare module 'next/dist/compiled/react-dom/server.browser' declare module 'next/dist/compiled/browserslist' declare module 'react-server-dom-webpack/client' diff --git a/packages/next/types/react-dom.d.ts b/packages/next/types/react-dom.d.ts index 4f9c1e69784a0..9b811922e4d55 100644 --- a/packages/next/types/react-dom.d.ts +++ b/packages/next/types/react-dom.d.ts @@ -1,5 +1,3 @@ -declare module 'react-dom/server.browser' - declare module 'react-dom/server.edge' { import type { JSX } from 'react' /** diff --git a/packages/next/webpack.config.js b/packages/next/webpack.config.js index 473aa75e8a8e3..615430a7cf2ea 100644 --- a/packages/next/webpack.config.js +++ b/packages/next/webpack.config.js @@ -13,7 +13,6 @@ const pagesExternals = [ 'react-dom/package.json', 'react-dom/client', 'react-dom/server', - 'react-dom/server.browser', 'react-dom/server.edge', 'react-server-dom-webpack/client', 'react-server-dom-webpack/client.edge', @@ -45,8 +44,6 @@ function makeAppAliases(reactChannel = '') { 'react-dom/static.browser$': `next/dist/compiled/react-dom${reactChannel}/static.browser`, // optimizations to ignore the legacy build of react-dom/server in `server.browser` build 'react-dom/server.edge$': `next/dist/build/webpack/alias/react-dom-server-edge${reactChannel}.js`, - // In Next.js runtime only use react-dom/server.edge - 'react-dom/server.browser$': 'react-dom/server.edge', // react-server-dom-webpack alias 'react-server-dom-turbopack/client$': `next/dist/compiled/react-server-dom-turbopack${reactChannel}/client`, 'react-server-dom-turbopack/client.edge$': `next/dist/compiled/react-server-dom-turbopack${reactChannel}/client.edge`, diff --git a/test/development/app-dir/ssr-in-rsc/ssr-in-rsc.test.ts b/test/development/app-dir/ssr-in-rsc/ssr-in-rsc.test.ts index 2f38cf34080cb..5602eee3721c7 100644 --- a/test/development/app-dir/ssr-in-rsc/ssr-in-rsc.test.ts +++ b/test/development/app-dir/ssr-in-rsc/ssr-in-rsc.test.ts @@ -39,8 +39,8 @@ describe('react-dom/server in React Server environment', () => { '/exports/app-code/react-dom-server-browser-explicit' ) - await assertNoRedbox(browser) if (isTurbopack) { + await assertNoRedbox(browser) if (isReactExperimental) { expect(await browser.elementByCss('main').text()) .toMatchInlineSnapshot(` @@ -83,47 +83,7 @@ describe('react-dom/server in React Server environment', () => { `) } } else { - if (isReactExperimental) { - expect(await browser.elementByCss('main').text()) - .toMatchInlineSnapshot(` - "{ - "default": [ - "renderToReadableStream", - "renderToStaticMarkup", - "renderToString", - "resume", - "version" - ], - "named": [ - "default", - "renderToReadableStream", - "renderToStaticMarkup", - "renderToString", - "resume", - "version" - ] - }" - `) - } else { - expect(await browser.elementByCss('main').text()) - .toMatchInlineSnapshot(` - "{ - "default": [ - "renderToReadableStream", - "renderToStaticMarkup", - "renderToString", - "version" - ], - "named": [ - "default", - "renderToReadableStream", - "renderToStaticMarkup", - "renderToString", - "version" - ] - }" - `) - } + await assertHasRedbox(browser) } const redbox = { description: await getRedboxDescription(browser), @@ -139,7 +99,7 @@ describe('react-dom/server in React Server environment', () => { } else { expect(redbox).toMatchInlineSnapshot(` { - "description": null, + "description": "Error: react-dom/server is not supported in React Server Components.", "source": null, } `)