Skip to content

Commit

Permalink
external client layer react pkgs
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Oct 20, 2022
1 parent 64b805a commit 3376fcf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions packages/next/build/webpack-config.ts
Expand Up @@ -129,7 +129,7 @@ const bundledReactImports = [
'react',
'react/jsx-runtime',
'react/jsx-dev-runtime',
'react-dom',
// 'react-dom',
'next/dist/compiled/react-server-dom-webpack/server.browser',
]

Expand Down Expand Up @@ -1056,13 +1056,17 @@ export default async function getBaseWebpackConfig(
// Treat react packages as external for SSR layer,
// then let require-hook mapping them to internals.
if (layer === WEBPACK_LAYERS.client) {
if (bundledReactImports.includes(request)) {
return (
'commonjs ' +
(request.startsWith('next/dist/compiled')
? request
: `next/dist/compiled/${request}`)
)
// console.log('WEBPACK_LAYERS.client', request)

if (
[
'react',
'react/jsx-runtime',
'react/jsx-dev-runtime',
'react-dom',
].includes(request)
) {
return `commonjs next/dist/compiled/${request}`
} else {
return
}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/client/script.tsx
Expand Up @@ -259,7 +259,7 @@ function Script(props: ScriptProps): JSX.Element | null {
// For the app directory, we need React Float to preload these scripts.
if (appDir) {
// Before interactive scripts need to be loaded by Next.js' runtime instead
// of native <script> tags, becasue they no longer have `defer`.
// of native <script> tags, because they no longer have `defer`.
if (strategy === 'beforeInteractive') {
if (!src) {
// For inlined scripts, we put the content in `children`.
Expand Down

0 comments on commit 3376fcf

Please sign in to comment.