@@ -5,7 +5,14 @@ import {
55 simpleSetCurrentInstance ,
66} from '@vue/runtime-core'
77import { normalizeBlock } from './block'
8- import { type VaporComponentInstance , devRender } from './component'
8+ import {
9+ type VaporComponent ,
10+ type VaporComponentInstance ,
11+ createComponent ,
12+ devRender ,
13+ mountComponent ,
14+ unmountComponent ,
15+ } from './component'
916import { insert , remove } from './dom/node'
1017
1118export function hmrRerender ( instance : VaporComponentInstance ) : void {
@@ -22,7 +29,22 @@ export function hmrRerender(instance: VaporComponentInstance): void {
2229 insert ( instance . block , parent , anchor )
2330}
2431
25- export function hmrReload ( instance : VaporComponentInstance ) : void {
26- // in parent block, find the corresponding block of this instance
27- // create new instance, replace
32+ export function hmrReload (
33+ instance : VaporComponentInstance ,
34+ newComp : VaporComponent ,
35+ ) : void {
36+ const normalized = normalizeBlock ( instance . block )
37+ const parent = normalized [ 0 ] . parentNode !
38+ const anchor = normalized [ normalized . length - 1 ] . nextSibling
39+ unmountComponent ( instance , parent )
40+ const prev = currentInstance
41+ simpleSetCurrentInstance ( instance . parent )
42+ const newInstance = createComponent (
43+ newComp ,
44+ instance . rawProps ,
45+ instance . rawSlots ,
46+ instance . isSingleRoot ,
47+ )
48+ simpleSetCurrentInstance ( prev , instance . parent )
49+ mountComponent ( newInstance , parent , anchor )
2850}
0 commit comments