Unverified Commit 7361dc46 authored by Will Binns-Smith's avatar Will Binns-Smith Committed by GitHub

Flight loader: use `normalModule.type` to determine module type (#76338)

This uses `normalModule.type` to determine the source module’s type
rather than accessing a value on `normalModule.parser`, which doesn’t
exist with rspack.
parent 20b4443f
...@@ -648,5 +648,6 @@ ...@@ -648,5 +648,6 @@
"647": "@rspack/core is not available. Please make sure `@next/plugin-rspack` is correctly installed.", "647": "@rspack/core is not available. Please make sure `@next/plugin-rspack` is correctly installed.",
"648": "@rspack/plugin-react-refresh is not available. Please make sure `@next/plugin-rspack` is correctly installed.", "648": "@rspack/plugin-react-refresh is not available. Please make sure `@next/plugin-rspack` is correctly installed.",
"649": "Cache handlers not initialized", "649": "Cache handlers not initialized",
"650": "experimental.nodeMiddleware" "650": "experimental.nodeMiddleware",
"651": "Unexpected module type %s"
} }
import type { webpack } from 'next/dist/compiled/webpack/webpack' import type { NormalModule, webpack } from 'next/dist/compiled/webpack/webpack'
import { RSC_MOD_REF_PROXY_ALIAS } from '../../../../lib/constants' import { RSC_MOD_REF_PROXY_ALIAS } from '../../../../lib/constants'
import { import {
BARREL_OPTIMIZATION_PREFIX, BARREL_OPTIMIZATION_PREFIX,
...@@ -97,7 +97,7 @@ export default function transformSource( ...@@ -97,7 +97,7 @@ export default function transformSource(
if (buildInfo.rsc?.type === RSC_MODULE_TYPES.client) { if (buildInfo.rsc?.type === RSC_MODULE_TYPES.client) {
const assumedSourceType = getAssumedSourceType( const assumedSourceType = getAssumedSourceType(
module, module,
(module.parser as javascript.JavascriptParser).sourceType sourceTypeFromModule(module)
) )
const clientRefs = buildInfo.rsc.clientRefs! const clientRefs = buildInfo.rsc.clientRefs!
...@@ -171,3 +171,17 @@ module.exports = createProxy(${stringifiedResourceKey}) ...@@ -171,3 +171,17 @@ module.exports = createProxy(${stringifiedResourceKey})
) )
this.callback(null, replacedSource, sourceMap) this.callback(null, replacedSource, sourceMap)
} }
function sourceTypeFromModule(module: NormalModule): SourceType {
const moduleType = module.type
switch (moduleType) {
case 'javascript/auto':
return 'auto'
case 'javascript/dynamic':
return 'script'
case 'javascript/esm':
return 'module'
default:
throw new Error('Unexpected module type ' + moduleType)
}
}
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