Skip to content

Commit

Permalink
refactor: remove edge condition for module proxy path (#54167)
Browse files Browse the repository at this point in the history
For edge-runtime we always bundle, and all the mapping of internal ESM files are configured in webpack. Adding a new alias of "next/dist/build" so we don't have to manually check the mapping path for module proxy
  • Loading branch information
huozhi committed Aug 17, 2023
1 parent 2360753 commit bc87328
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ export default async function getBaseWebpackConfig(
// let this alias hit before `next` alias.
...(isEdgeServer
? {
'next/dist/build': 'next/dist/esm/build',
'next/dist/client': 'next/dist/esm/client',
'next/dist/shared': 'next/dist/esm/shared',
'next/dist/pages': 'next/dist/esm/pages',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { getRSCModuleInformation } from '../../../analysis/get-page-static-info'
import { getModuleBuildInfo } from '../get-module-build-info'

const noopHeadPath = require.resolve('next/dist/client/components/noop-head')
// For edge runtime it will be aliased to esm version by webpack
const MODULE_PROXY_PATH =
'next/dist/build/webpack/loaders/next-flight-loader/module-proxy'

export default function transformSource(
this: any,
Expand All @@ -16,11 +19,6 @@ export default function transformSource(
throw new Error('Expected source to have been transformed to a string.')
}

const moduleProxy =
this._compiler.name === 'edge-server'
? 'next/dist/esm/build/webpack/loaders/next-flight-loader/module-proxy'
: 'next/dist/build/webpack/loaders/next-flight-loader/module-proxy'

// Assign the RSC meta information to buildInfo.
// Exclude next internal files which are not marked as client files
const buildInfo = getModuleBuildInfo(this._module)
Expand Down Expand Up @@ -62,7 +60,7 @@ export default function transformSource(
}

let esmSource = `\
import { createProxy } from "${moduleProxy}"
import { createProxy } from "${MODULE_PROXY_PATH}"
const proxy = createProxy(String.raw\`${this.resourcePath}\`)
// Accessing the __esModule property and exporting $$typeof are required here.
Expand Down Expand Up @@ -102,7 +100,7 @@ export { e${cnt++} as ${ref} };`

this.callback(
null,
source.replace(RSC_MOD_REF_PROXY_ALIAS, moduleProxy),
source.replace(RSC_MOD_REF_PROXY_ALIAS, MODULE_PROXY_PATH),
sourceMap
)
}

0 comments on commit bc87328

Please sign in to comment.