@@ -414,7 +414,7 @@ async function fetchUpdate({
414
414
return
415
415
}
416
416
417
- const moduleMap = new Map < string , ModuleNamespace > ( )
417
+ let fetchedModule : ModuleNamespace | undefined
418
418
const isSelfUpdate = path === acceptedPath
419
419
420
420
// determine the qualified callbacks before we re-import the modules
@@ -423,28 +423,26 @@ async function fetchUpdate({
423
423
)
424
424
425
425
if ( isSelfUpdate || qualifiedCallbacks . length > 0 ) {
426
- const dep = acceptedPath
427
- const disposer = disposeMap . get ( dep )
428
- if ( disposer ) await disposer ( dataMap . get ( dep ) )
429
- const [ path , query ] = dep . split ( `?` )
426
+ const disposer = disposeMap . get ( acceptedPath )
427
+ if ( disposer ) await disposer ( dataMap . get ( acceptedPath ) )
428
+ const [ acceptedPathWithoutQuery , query ] = acceptedPath . split ( `?` )
430
429
try {
431
- const newMod : ModuleNamespace = await import (
430
+ fetchedModule = await import (
432
431
/* @vite -ignore */
433
432
base +
434
- path . slice ( 1 ) +
433
+ acceptedPathWithoutQuery . slice ( 1 ) +
435
434
`?${ explicitImportRequired ? 'import&' : '' } t=${ timestamp } ${
436
435
query ? `&${ query } ` : ''
437
436
} `
438
437
)
439
- moduleMap . set ( dep , newMod )
440
438
} catch ( e ) {
441
- warnFailedFetch ( e , dep )
439
+ warnFailedFetch ( e , acceptedPath )
442
440
}
443
441
}
444
442
445
443
return ( ) => {
446
444
for ( const { deps, fn } of qualifiedCallbacks ) {
447
- fn ( deps . map ( ( dep ) => moduleMap . get ( dep ) ) )
445
+ fn ( deps . map ( ( dep ) => ( dep === acceptedPath ? fetchedModule : undefined ) ) )
448
446
}
449
447
const loggedPath = isSelfUpdate ? path : `${ acceptedPath } via ${ path } `
450
448
console . debug ( `[vite] hot updated: ${ loggedPath } ` )
@@ -527,10 +525,10 @@ export function createHotContext(ownerPath: string): ViteHotContext {
527
525
accept ( deps ?: any , callback ?: any ) {
528
526
if ( typeof deps === 'function' || ! deps ) {
529
527
// self-accept: hot.accept(() => {})
530
- acceptDeps ( [ ownerPath ] , ( [ mod ] ) => deps && deps ( mod ) )
528
+ acceptDeps ( [ ownerPath ] , ( [ mod ] ) => deps ?. ( mod ) )
531
529
} else if ( typeof deps === 'string' ) {
532
530
// explicit deps
533
- acceptDeps ( [ deps ] , ( [ mod ] ) => callback && callback ( mod ) )
531
+ acceptDeps ( [ deps ] , ( [ mod ] ) => callback ?. ( mod ) )
534
532
} else if ( Array . isArray ( deps ) ) {
535
533
acceptDeps ( deps , callback )
536
534
} else {
@@ -540,8 +538,8 @@ export function createHotContext(ownerPath: string): ViteHotContext {
540
538
541
539
// export names (first arg) are irrelevant on the client side, they're
542
540
// extracted in the server for propagation
543
- acceptExports ( _ : string | readonly string [ ] , callback ?: any ) {
544
- acceptDeps ( [ ownerPath ] , callback && ( ( [ mod ] ) => callback ( mod ) ) )
541
+ acceptExports ( _ , callback ) {
542
+ acceptDeps ( [ ownerPath ] , ( [ mod ] ) => callback ?. ( mod ) )
545
543
} ,
546
544
547
545
dispose ( cb ) {
0 commit comments