Skip to content

Commit 87fd798

Browse files
committed
fix(rsc): use a single source-read path for export-name scan
1 parent bc48c4d commit 87fd798

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

packages/plugin-rsc/src/plugin.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,20 +1413,16 @@ async function collectExportNames(
14131413
if (seen.has(resolvedId)) return []
14141414
seen.add(resolvedId)
14151415

1416-
// `this.load`'s ModuleInfo.code is build-only. In dev mode, the dev
1417-
// environment's `transformRequest` returns module-runner-specific output
1418-
// (e.g. `__vite_ssr_exportName__("X", ...)` instead of `export ... from`),
1419-
// which the AST walk below can't read. Use a plain TS/JSX-aware transform
1420-
// on the source instead so we get standard ESM exports to walk.
1416+
// Read the source from disk and strip TS/JSX so the AST walk below sees
1417+
// standard ESM exports. We don't go through `this.load` /
1418+
// `transformRequest` here — in dev they return module-runner output
1419+
// (`__vite_ssr_exportName__(...)`) the walker can't read, and on build
1420+
// there's no practical benefit over reading the source directly for the
1421+
// simple TS/JSX modules we care about.
14211422
let moduleCode: string | undefined
14221423
try {
1423-
if (ctx.environment.mode === 'dev') {
1424-
const raw = await fs.promises.readFile(resolvedId, 'utf-8')
1425-
moduleCode = await transformSourceForExportScan(raw, resolvedId)
1426-
} else {
1427-
const moduleInfo = await ctx.load({ id: resolvedId })
1428-
moduleCode = moduleInfo.code ?? undefined
1429-
}
1424+
const raw = await fs.promises.readFile(resolvedId, 'utf-8')
1425+
moduleCode = await transformSourceForExportScan(raw, resolvedId)
14301426
} catch {
14311427
return []
14321428
}

0 commit comments

Comments
 (0)