From e520c1d461d43d4c51bf809df387bfdc285734fa Mon Sep 17 00:00:00 2001 From: Oleg Shibaev Date: Sat, 15 Nov 2025 19:46:22 +0400 Subject: [PATCH 1/2] fix: fix hmr of dynamically loaded vue sfc modules in apps with tailwind --- packages/plugin-vue/src/handleHotUpdate.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index 8e133229..46d1c0b7 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -336,7 +336,17 @@ function getMainModule(modules: ModuleNode[]) { // #9341 // We pick the module with the shortest URL in order to pick the module // with the lowest number of query parameters. + // https://github.com/vitejs/vite-plugin-vue/issues/701 + // Prefer type: 'js' modules, since tailwind can add type: 'asset' modules + // which can have the same url length and come first in the array + // in certain cases .sort((m1, m2) => { + if (m1.type !== m2.type) { + if (m1.type === 'js' || m2.type === 'js') { + return m1.type === 'js' ? -1 : 1 + } + } + return m1.url.length - m2.url.length })[0] ) From 971c15c492b94d2c2d95596c456db93ede0d1a6c Mon Sep 17 00:00:00 2001 From: Oleg Shibaev Date: Mon, 17 Nov 2025 17:37:48 +0400 Subject: [PATCH 2/2] fix: filter out non-js modules instead of sorting --- packages/plugin-vue/src/handleHotUpdate.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index 46d1c0b7..3f9fd1b3 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -332,28 +332,24 @@ function hasScriptChanged(prev: SFCDescriptor, next: SFCDescriptor): boolean { function getMainModule(modules: ModuleNode[]) { return ( modules - .filter((m) => !/type=/.test(m.url) || /type=script/.test(m.url)) + .filter( + (m) => + m.type === 'js' && + (!/type=/.test(m.url) || /type=script/.test(m.url)), + ) // #9341 // We pick the module with the shortest URL in order to pick the module // with the lowest number of query parameters. - // https://github.com/vitejs/vite-plugin-vue/issues/701 - // Prefer type: 'js' modules, since tailwind can add type: 'asset' modules - // which can have the same url length and come first in the array - // in certain cases .sort((m1, m2) => { - if (m1.type !== m2.type) { - if (m1.type === 'js' || m2.type === 'js') { - return m1.type === 'js' ? -1 : 1 - } - } - return m1.url.length - m2.url.length })[0] ) } function getScriptModule(modules: ModuleNode[]) { - return modules.find((m) => /type=script.*&lang\.\w+$/.test(m.url)) + return modules.find( + (m) => m.type === 'js' && /type=script.*&lang\.\w+$/.test(m.url), + ) } export function handleTypeDepChange(