Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/plugin-vue/src/handleHotUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of sorting the modules here, I think we can filter out the non-js modules in the .filter above.

.filter((m) => m.type === 'js' && (!/type=/.test(m.url) || /type=script/.test(m.url)))

Further more, I think we should a add the same condition to other places that uses modules variable. I think we should add jsModules variable that has m.type === 'js' modules and use that instead.

Copy link
Author

@unshame unshame Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the filtering in two places where I found modules being used.

I'm assuming the places where style, template and custom blocks are being handled should not have this condition added?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All blocks are transformed to JS and has type: 'js', so we can / should add the condition for them as well.

We can also remove this condition because if the module has ?direct, it will have type: 'css'.

!directRequestRE.test(m.url),


return m1.url.length - m2.url.length
})[0]
)
Expand Down