@@ -41,7 +41,13 @@ interface HMRRecord {
41
41
const map : Map < string , HMRRecord > = new Map ( )
42
42
43
43
export function registerHMR ( instance : ComponentInternalInstance ) {
44
- map . get ( instance . type . __hmrId ! ) ! . instances . add ( instance )
44
+ const id = instance . type . __hmrId !
45
+ let record = map . get ( id )
46
+ if ( ! record ) {
47
+ createRecord ( id , instance . type as ComponentOptions )
48
+ record = map . get ( id ) !
49
+ }
50
+ record . instances . add ( instance )
45
51
}
46
52
47
53
export function unregisterHMR ( instance : ComponentInternalInstance ) {
@@ -60,9 +66,11 @@ function createRecord(id: string, comp: ComponentOptions): boolean {
60
66
}
61
67
62
68
function rerender ( id : string , newRender ?: RenderFunction ) {
69
+ const record = map . get ( id )
70
+ if ( ! record ) return
63
71
// Array.from creates a snapshot which avoids the set being mutated during
64
72
// updates
65
- Array . from ( map . get ( id ) ! . instances ) . forEach ( instance => {
73
+ Array . from ( record . instances ) . forEach ( instance => {
66
74
if ( newRender ) {
67
75
instance . render = newRender
68
76
}
@@ -75,7 +83,8 @@ function rerender(id: string, newRender?: RenderFunction) {
75
83
}
76
84
77
85
function reload ( id : string , newComp : ComponentOptions ) {
78
- const record = map . get ( id ) !
86
+ const record = map . get ( id )
87
+ if ( ! record ) return
79
88
// 1. Update existing comp definition to match new one
80
89
const comp = record . comp
81
90
Object . assign ( comp , newComp )
0 commit comments