Skip to content

Commit f76706b

Browse files
authored
fix: prevent multiple processing of await plugin output (#328)
1 parent abfbed0 commit f76706b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/plugins/pluginDevProxyModuleTopLevelAwait.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ import { Plugin } from 'vite';
88

99
export function PluginDevProxyModuleTopLevelAwait(): Plugin {
1010
const filterFunction = createFilter();
11+
const processedFlag = '/* already-processed-by-dev-proxy-module-top-level-await */';
12+
1113
return {
1214
name: 'dev-proxy-module-top-level-await',
1315
apply: 'serve',
1416
transform(code: string, id: string): { code: string; map: any } | null {
17+
if (code.includes(processedFlag)) {
18+
return null;
19+
}
1520
if (!code.includes('/*mf top-level-await placeholder replacement mf*/')) {
1621
return null;
1722
}
@@ -90,8 +95,9 @@ export function PluginDevProxyModuleTopLevelAwait(): Plugin {
9095
}
9196
},
9297
});
98+
const transformedCode = magicString.toString();
9399
return {
94-
code: magicString.toString(),
100+
code: `${processedFlag}\n${transformedCode}`,
95101
map: magicString.generateMap({ hires: true }),
96102
};
97103
},

0 commit comments

Comments
 (0)