Skip to content

Commit 0b8b63a

Browse files
committed
perf: optimize hmr logic
1 parent 81d76d2 commit 0b8b63a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

packages/complex-types/src/index.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,16 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (
4141
return;
4242
}
4343

44-
let cached: Promise<string> | undefined;
4544
ctx.read = async () => {
46-
cached ??= (async () => {
47-
const code = await readAndUpdateLanguage();
48-
const result = transform(code, file, resolvedOptions);
45+
const code = await readAndUpdateLanguage();
46+
const result = transform(code, file, resolvedOptions);
4947

50-
return result?.code ?? code;
51-
})();
52-
53-
return cached;
48+
return result?.code ?? code;
5449
};
5550

56-
for (const mod of ctx.modules) {
57-
ctx.server.moduleGraph.invalidateModule(mod);
51+
const sfcModule = ctx.modules.find((mod) => mod.file === file);
52+
if (sfcModule) {
53+
return [sfcModule];
5854
}
5955

6056
return ctx.modules;

0 commit comments

Comments
 (0)