File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -1880,6 +1880,26 @@ describe('SSR hydration', () => {
18801880 expect ( root . innerHTML ) . toBe ( '<div><div>bar</div></div>' )
18811881 } )
18821882
1883+ test ( 'hmr root reload' , async ( ) => {
1884+ const appId = 'test-app-id'
1885+ const App = {
1886+ __hmrId : appId ,
1887+ template : `<div>foo</div>` ,
1888+ }
1889+
1890+ const root = document . createElement ( 'div' )
1891+ root . innerHTML = await renderToString ( h ( App ) )
1892+ createSSRApp ( App ) . mount ( root )
1893+ expect ( root . innerHTML ) . toBe ( '<div>foo</div>' )
1894+
1895+ reload ( appId , {
1896+ __hmrId : appId ,
1897+ template : `<div>bar</div>` ,
1898+ } )
1899+ await nextTick ( )
1900+ expect ( root . innerHTML ) . toBe ( '<div>bar</div>' )
1901+ } )
1902+
18831903 describe ( 'mismatch handling' , ( ) => {
18841904 test ( 'text node' , ( ) => {
18851905 const { container } = mountWithHydration ( `foo` , ( ) => 'bar' )
Original file line number Diff line number Diff line change @@ -383,13 +383,12 @@ export function createAppAPI<HostElement>(
383383 // HMR root reload
384384 if ( __DEV__ ) {
385385 context . reload = ( ) => {
386+ const cloned = cloneVNode ( vnode )
387+ // avoid hydration for hmr updating
388+ cloned . el = null
386389 // casting to ElementNamespace because TS doesn't guarantee type narrowing
387390 // over function boundaries
388- render (
389- cloneVNode ( vnode ) ,
390- rootContainer ,
391- namespace as ElementNamespace ,
392- )
391+ render ( cloned , rootContainer , namespace as ElementNamespace )
393392 }
394393 }
395394
You can’t perform that action at this time.
0 commit comments