Skip to content

Commit 971c15c

Browse files
committed
fix: filter out non-js modules instead of sorting
1 parent e520c1d commit 971c15c

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

packages/plugin-vue/src/handleHotUpdate.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,28 +332,24 @@ function hasScriptChanged(prev: SFCDescriptor, next: SFCDescriptor): boolean {
332332
function getMainModule(modules: ModuleNode[]) {
333333
return (
334334
modules
335-
.filter((m) => !/type=/.test(m.url) || /type=script/.test(m.url))
335+
.filter(
336+
(m) =>
337+
m.type === 'js' &&
338+
(!/type=/.test(m.url) || /type=script/.test(m.url)),
339+
)
336340
// #9341
337341
// We pick the module with the shortest URL in order to pick the module
338342
// with the lowest number of query parameters.
339-
// https://github.com/vitejs/vite-plugin-vue/issues/701
340-
// Prefer type: 'js' modules, since tailwind can add type: 'asset' modules
341-
// which can have the same url length and come first in the array
342-
// in certain cases
343343
.sort((m1, m2) => {
344-
if (m1.type !== m2.type) {
345-
if (m1.type === 'js' || m2.type === 'js') {
346-
return m1.type === 'js' ? -1 : 1
347-
}
348-
}
349-
350344
return m1.url.length - m2.url.length
351345
})[0]
352346
)
353347
}
354348

355349
function getScriptModule(modules: ModuleNode[]) {
356-
return modules.find((m) => /type=script.*&lang\.\w+$/.test(m.url))
350+
return modules.find(
351+
(m) => m.type === 'js' && /type=script.*&lang\.\w+$/.test(m.url),
352+
)
357353
}
358354

359355
export function handleTypeDepChange(

0 commit comments

Comments
 (0)