File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,30 @@ describe('suspense hydration', () => {
9797 } ) ;
9898 } ) ;
9999
100+ it ( 'should leave DOM untouched when suspending while hydrating' , ( ) => {
101+ scratch . innerHTML = '<!-- test --><div>Hello</div>' ;
102+ clearLog ( ) ;
103+
104+ const [ Lazy , resolve ] = createLazy ( ) ;
105+ hydrate (
106+ < Suspense >
107+ < Lazy />
108+ </ Suspense > ,
109+ scratch
110+ ) ;
111+ rerender ( ) ; // Flush rerender queue to mimic what preact will really do
112+ expect ( scratch . innerHTML ) . to . equal ( '<!-- test --><div>Hello</div>' ) ;
113+ expect ( getLog ( ) ) . to . deep . equal ( [ ] ) ;
114+ clearLog ( ) ;
115+
116+ return resolve ( ( ) => < div > Hello</ div > ) . then ( ( ) => {
117+ rerender ( ) ;
118+ expect ( scratch . innerHTML ) . to . equal ( '<!-- test --><div>Hello</div>' ) ;
119+ expect ( getLog ( ) ) . to . deep . equal ( [ ] ) ;
120+ clearLog ( ) ;
121+ } ) ;
122+ } ) ;
123+
100124 it ( 'should properly attach event listeners when suspending while hydrating' , ( ) => {
101125 scratch . innerHTML = '<div>Hello</div><div>World</div>' ;
102126 clearLog ( ) ;
Original file line number Diff line number Diff line change @@ -273,13 +273,15 @@ export function diff(
273273 newVNode . _original = null ;
274274 // if hydrating or creating initial tree, bailout preserves DOM:
275275 if ( isHydrating || excessDomChildren != null ) {
276- newVNode . _dom = oldDom ;
277276 newVNode . _flags |= isHydrating
278277 ? MODE_HYDRATE | MODE_SUSPENDED
279278 : MODE_HYDRATE ;
279+
280+ while ( oldDom && oldDom . nodeType === 8 && oldDom . nextSibling ) {
281+ oldDom = oldDom . nextSibling ;
282+ }
280283 excessDomChildren [ excessDomChildren . indexOf ( oldDom ) ] = null ;
281- // ^ could possibly be simplified to:
282- // excessDomChildren.length = 0;
284+ newVNode . _dom = oldDom ;
283285 } else {
284286 newVNode . _dom = oldVNode . _dom ;
285287 newVNode . _children = oldVNode . _children ;
You can’t perform that action at this time.
0 commit comments