File tree 2 files changed +24
-5
lines changed
2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -1880,6 +1880,26 @@ describe('SSR hydration', () => {
1880
1880
expect ( root . innerHTML ) . toBe ( '<div><div>bar</div></div>' )
1881
1881
} )
1882
1882
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
+
1883
1903
describe ( 'mismatch handling' , ( ) => {
1884
1904
test ( 'text node' , ( ) => {
1885
1905
const { container } = mountWithHydration ( `foo` , ( ) => 'bar' )
Original file line number Diff line number Diff line change @@ -383,13 +383,12 @@ export function createAppAPI<HostElement>(
383
383
// HMR root reload
384
384
if ( __DEV__ ) {
385
385
context . reload = ( ) => {
386
+ const cloned = cloneVNode ( vnode )
387
+ // avoid hydration for hmr updating
388
+ cloned . el = null
386
389
// casting to ElementNamespace because TS doesn't guarantee type narrowing
387
390
// over function boundaries
388
- render (
389
- cloneVNode ( vnode ) ,
390
- rootContainer ,
391
- namespace as ElementNamespace ,
392
- )
391
+ render ( cloned , rootContainer , namespace as ElementNamespace )
393
392
}
394
393
}
395
394
You can’t perform that action at this time.
0 commit comments