@@ -32,10 +32,13 @@ import {
3232 withCtx ,
3333 withDirectives ,
3434} from '@vue/runtime-dom'
35+ import type { HMRRuntime } from '../src/hmr'
3536import { type SSRContext , renderToString } from '@vue/server-renderer'
3637import { PatchFlags , normalizeStyle } from '@vue/shared'
3738import { vShowOriginalDisplay } from '../../runtime-dom/src/directives/vShow'
38- import { expect } from 'vitest'
39+
40+ declare var __VUE_HMR_RUNTIME__ : HMRRuntime
41+ const { createRecord, reload } = __VUE_HMR_RUNTIME__
3942
4043function mountWithHydration ( html : string , render : ( ) => any ) {
4144 const container = document . createElement ( 'div' )
@@ -1843,6 +1846,40 @@ describe('SSR hydration', () => {
18431846 }
18441847 } )
18451848
1849+ test ( 'hmr reload child wrapped in KeepAlive' , async ( ) => {
1850+ const id = 'child-reload'
1851+ const Child = {
1852+ __hmrId : id ,
1853+ template : `<div>foo</div>` ,
1854+ }
1855+ createRecord ( id , Child )
1856+
1857+ const appId = 'test-app-id'
1858+ const App = {
1859+ __hmrId : appId ,
1860+ components : { Child } ,
1861+ template : `
1862+ <div>
1863+ <KeepAlive>
1864+ <Child />
1865+ </KeepAlive>
1866+ </div>
1867+ ` ,
1868+ }
1869+
1870+ const root = document . createElement ( 'div' )
1871+ root . innerHTML = await renderToString ( h ( App ) )
1872+ createSSRApp ( App ) . mount ( root )
1873+ expect ( root . innerHTML ) . toBe ( '<div><div>foo</div></div>' )
1874+
1875+ reload ( id , {
1876+ __hmrId : id ,
1877+ template : `<div>bar</div>` ,
1878+ } )
1879+ await nextTick ( )
1880+ expect ( root . innerHTML ) . toBe ( '<div><div>bar</div></div>' )
1881+ } )
1882+
18461883 describe ( 'mismatch handling' , ( ) => {
18471884 test ( 'text node' , ( ) => {
18481885 const { container } = mountWithHydration ( `foo` , ( ) => 'bar' )
0 commit comments