@@ -19,8 +19,6 @@ import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
1919
2020const debug = createDebug ( 'vite:hmr' )
2121
22- const directRequestRE = / [ & ? ] d i r e c t \b /
23-
2422/**
2523 * Vite-specific HMR handling
2624 */
@@ -40,17 +38,19 @@ export async function handleHotUpdate(
4038 const { descriptor } = createDescriptor ( file , content , options , true )
4139
4240 let needRerender = false
41+ const nonJsModules = modules . filter ( ( m ) => m . type !== 'js' )
42+ const jsModules = modules . filter ( ( m ) => m . type === 'js' )
4343 const affectedModules = new Set < ModuleNode | undefined > (
44- modules . filter ( ( mod ) => mod . type !== 'js' ) , // this plugin does not handle non-js modules
44+ nonJsModules , // this plugin does not handle non-js modules
4545 )
46- const mainModule = getMainModule ( modules )
47- const templateModule = modules . find ( ( m ) => / t y p e = t e m p l a t e / . test ( m . url ) )
46+ const mainModule = getMainModule ( jsModules )
47+ const templateModule = jsModules . find ( ( m ) => / t y p e = t e m p l a t e / . test ( m . url ) )
4848
4949 // trigger resolveScript for descriptor so that we'll have the AST ready
5050 resolveScript ( 'vite' , descriptor , { ...options , ssr : false } , customElement )
5151 const scriptChanged = hasScriptChanged ( prevDescriptor , descriptor )
5252 if ( scriptChanged ) {
53- affectedModules . add ( getScriptModule ( modules ) || mainModule )
53+ affectedModules . add ( getScriptModule ( jsModules ) || mainModule )
5454 }
5555
5656 if ( ! isEqualBlock ( descriptor . template , prevDescriptor . template ) ) {
@@ -91,11 +91,10 @@ export async function handleHotUpdate(
9191 const prev = prevStyles [ i ]
9292 if ( ! prev || ! isEqualBlock ( prev , next ) ) {
9393 didUpdateStyle = true
94- const mod = modules . find (
94+ const mod = jsModules . find (
9595 ( m ) =>
9696 m . url . includes ( `type=style&index=${ i } ` ) &&
97- m . url . endsWith ( `.${ next . lang || 'css' } ` ) &&
98- ! directRequestRE . test ( m . url ) ,
97+ m . url . endsWith ( `.${ next . lang || 'css' } ` ) ,
9998 )
10099 if ( mod ) {
101100 affectedModules . add ( mod )
@@ -122,7 +121,7 @@ export async function handleHotUpdate(
122121 for ( const [ i , next ] of nextCustoms . entries ( ) ) {
123122 const prev = prevCustoms [ i ]
124123 if ( ! prev || ! isEqualBlock ( prev , next ) ) {
125- const mod = modules . find ( ( m ) =>
124+ const mod = jsModules . find ( ( m ) =>
126125 m . url . includes ( `type=${ prev . type } &index=${ i } ` ) ,
127126 )
128127 if ( mod ) {
@@ -323,9 +322,9 @@ function hasScriptChanged(prev: SFCDescriptor, next: SFCDescriptor): boolean {
323322 return false
324323}
325324
326- function getMainModule ( modules : ModuleNode [ ] ) {
325+ function getMainModule ( jsModules : ModuleNode [ ] ) {
327326 return (
328- modules
327+ jsModules
329328 . filter ( ( m ) => ! / t y p e = / . test ( m . url ) || / t y p e = s c r i p t / . test ( m . url ) )
330329 // #9341
331330 // We pick the module with the shortest URL in order to pick the module
@@ -336,8 +335,8 @@ function getMainModule(modules: ModuleNode[]) {
336335 )
337336}
338337
339- function getScriptModule ( modules : ModuleNode [ ] ) {
340- return modules . find ( ( m ) => / t y p e = s c r i p t .* & l a n g \. \w + $ / . test ( m . url ) )
338+ function getScriptModule ( jsModules : ModuleNode [ ] ) {
339+ return jsModules . find ( ( m ) => / t y p e = s c r i p t .* & l a n g \. \w + $ / . test ( m . url ) )
341340}
342341
343342export function handleTypeDepChange (
0 commit comments