Skip to content

Commit 1dcfff6

Browse files
committed
fix: ensure HMR updates styles when SFC is treated as a type dependency
1 parent b5b9786 commit 1dcfff6

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/core/handleHotUpdate.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export async function handleHotUpdate(
2828
{ file, modules, read }: HmrContext,
2929
options: ResolvedOptions,
3030
customElement: boolean,
31+
typeDepModules?: ModuleNode[],
3132
): Promise<ModuleNode[] | undefined> {
3233
const prevDescriptor = getDescriptor(file, options, false, true)
3334
if (!prevDescriptor) {
@@ -167,7 +168,9 @@ export async function handleHotUpdate(
167168
}
168169
debug(`[vue:update(${updateType.join('&')})] ${file}`)
169170
}
170-
return [...affectedModules].filter(Boolean) as ModuleNode[]
171+
return [...affectedModules, ...(typeDepModules || [])].filter(
172+
Boolean,
173+
) as ModuleNode[]
171174
}
172175

173176
export function isEqualBlock(a: SFCBlock | null, b: SFCBlock | null): boolean {

src/core/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import {
77
type UnpluginContextMeta,
88
type UnpluginInstance,
99
} from 'unplugin'
10-
import { createFilter, normalizePath, type ViteDevServer } from 'vite'
10+
import {
11+
createFilter,
12+
normalizePath,
13+
type ModuleNode,
14+
type ViteDevServer,
15+
} from 'vite'
1116
import { version } from '../../package.json'
1217
import { resolveCompiler } from '../core/compiler'
1318
import { EXPORT_HELPER_ID, helperCode } from '../core/helper'
@@ -248,14 +253,22 @@ export const plugin: UnpluginInstance<Options | undefined, false> =
248253
if (options.value.compiler.invalidateTypeCache) {
249254
options.value.compiler.invalidateTypeCache(ctx.file)
250255
}
256+
257+
let typeDepModules: ModuleNode[] | undefined
258+
const matchesFilter = filter.value(ctx.file)
251259
if (typeDepToSFCMap.has(ctx.file)) {
252-
return handleTypeDepChange(typeDepToSFCMap.get(ctx.file)!, ctx)
260+
typeDepModules = handleTypeDepChange(
261+
typeDepToSFCMap.get(ctx.file)!,
262+
ctx,
263+
)
264+
if (!matchesFilter) return typeDepModules
253265
}
254-
if (filter.value(ctx.file)) {
266+
if (matchesFilter) {
255267
return handleHotUpdate(
256268
ctx,
257269
options.value,
258270
customElementFilter.value(ctx.file),
271+
typeDepModules,
259272
)
260273
}
261274
},

0 commit comments

Comments
 (0)