diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index b5ad90c5..be7414f9 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -1,5 +1,5 @@ { - "name": "@vitejs/plugin-vue", + "name": "plugin-vue-rolldown-hmr-demo", "version": "5.0.5", "license": "MIT", "author": "Evan You", diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index 6ccd0ad8..f1613615 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -8,6 +8,7 @@ import type * as t from '@babel/types' import { cache, + clearPrevDescriptor, createDescriptor, getDescriptor, invalidateDescriptor, @@ -341,6 +342,7 @@ export function handleTypeDepChange( ): ModuleNode[] { const affected = new Set() for (const file of affectedComponents) { + clearPrevDescriptor(file) invalidateScript(file) const mods = moduleGraph.getModulesByFile(file) if (mods) { diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index e9577605..6421f990 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -12,6 +12,7 @@ import { createDescriptor, getDescriptor, getPrevDescriptor, + setPrevDescriptor, setSrcDescriptor, } from './utils/descriptorCache' import { @@ -152,6 +153,7 @@ export async function transformMain( if (prevDescriptor && isOnlyTemplateChanged(prevDescriptor, descriptor)) { output.push(`export const _rerender_only = true`) } + setPrevDescriptor(filename, descriptor) output.push( `import.meta.hot.accept(mod => {`, ` if (!mod) return`, diff --git a/packages/plugin-vue/src/utils/descriptorCache.ts b/packages/plugin-vue/src/utils/descriptorCache.ts index 7f643d1b..6ef9a602 100644 --- a/packages/plugin-vue/src/utils/descriptorCache.ts +++ b/packages/plugin-vue/src/utils/descriptorCache.ts @@ -52,6 +52,14 @@ export function invalidateDescriptor(filename: string, hmr = false): void { } } +export function setPrevDescriptor(filename: string, descriptor: SFCDescriptor): void { + prevCache.set(filename, descriptor) +} + +export function clearPrevDescriptor(filename: string): void { + prevCache.delete(filename) +} + export function getDescriptor( filename: string, options: ResolvedOptions,