@@ -75,21 +75,25 @@ export function diff(
7575 if ( newVNode . constructor != UNDEFINED ) return NULL ;
7676
7777 // If the previous diff bailed out, resume creating/hydrating.
78- if ( oldVNode . _flags & MODE_SUSPENDED ) {
79- isHydrating = ! ! ( oldVNode . _flags & MODE_HYDRATE ) ;
80- if ( oldVNode . _component . _excess ) {
81- excessDomChildren = oldVNode . _component . _excess ;
82- oldDom = newVNode . _dom = oldVNode . _dom = excessDomChildren [ 0 ] ;
83- oldVNode . _component . _excess = null ;
84- }
78+ if (
79+ oldVNode . _flags & MODE_SUSPENDED &&
80+ // @ts -expect-error This is 1 or 0 (true or false)
81+ ( isHydrating = oldVNode . _flags & MODE_HYDRATE )
82+ ) {
83+ excessDomChildren = oldVNode . _component . _excess ;
84+ oldDom = excessDomChildren [ 0 ] ;
85+ oldVNode . _component . _excess = NULL ;
8586 }
8687
8788 if ( ( tmp = options . _diff ) ) tmp ( newVNode ) ;
8889
8990 outer: if ( typeof newType == 'function' ) {
9091 try {
91- let c , isNew , oldProps , oldState , snapshot , clearProcessingException ;
92- let newProps = newVNode . props ;
92+ let c ,
93+ oldProps ,
94+ oldState ,
95+ snapshot ,
96+ newProps = newVNode . props ;
9397 const isClassComponent =
9498 'prototype' in newType && newType . prototype . render ;
9599
@@ -108,7 +112,6 @@ export function diff(
108112 c = newVNode . _component = oldVNode . _component ;
109113 if ( c . _bits & COMPONENT_PENDING_ERROR ) {
110114 c . _bits |= COMPONENT_PROCESSING_EXCEPTION ;
111- clearProcessingException = true ;
112115 }
113116 } else {
114117 // Instantiate the new component
@@ -131,7 +134,6 @@ export function diff(
131134 if ( ! c . state ) c . state = { } ;
132135 c . context = componentContext ;
133136 c . _globalContext = globalContext ;
134- isNew = true ;
135137 c . _bits |= COMPONENT_DIRTY ;
136138 c . _renderCallbacks = [ ] ;
137139 c . _stateCallbacks = [ ] ;
@@ -158,7 +160,7 @@ export function diff(
158160 c . _vnode = newVNode ;
159161
160162 // Invoke pre-render lifecycle methods
161- if ( isNew ) {
163+ if ( ! oldVNode . _component ) {
162164 if (
163165 isClassComponent &&
164166 newType . getDerivedStateFromProps == NULL &&
@@ -268,21 +270,24 @@ export function diff(
268270 globalContext = assign ( { } , globalContext , c . getChildContext ( ) ) ;
269271 }
270272
271- if ( isClassComponent && ! isNew && c . getSnapshotBeforeUpdate != NULL ) {
273+ if (
274+ isClassComponent &&
275+ oldVNode . _component &&
276+ c . getSnapshotBeforeUpdate != NULL
277+ ) {
272278 snapshot = c . getSnapshotBeforeUpdate ( oldProps , oldState ) ;
273279 }
274280
275281 let isTopLevelFragment =
276282 tmp != NULL && tmp . type === Fragment && tmp . key == NULL ;
277- let renderResult = tmp ;
278283
279284 if ( isTopLevelFragment ) {
280- renderResult = cloneNode ( tmp . props . children ) ;
285+ tmp = cloneNode ( tmp . props . children ) ;
281286 }
282287
283288 oldDom = diffChildren (
284289 parentDom ,
285- isArray ( renderResult ) ? renderResult : [ renderResult ] ,
290+ isArray ( tmp ) ? tmp : [ tmp ] ,
286291 newVNode ,
287292 oldVNode ,
288293 globalContext ,
@@ -302,7 +307,7 @@ export function diff(
302307 commitQueue . push ( c ) ;
303308 }
304309
305- if ( clearProcessingException ) {
310+ if ( c . _bits & COMPONENT_PENDING_ERROR ) {
306311 c . _bits &= ~ ( COMPONENT_PROCESSING_EXCEPTION | COMPONENT_PENDING_ERROR ) ;
307312 }
308313 } catch ( e ) {
@@ -311,7 +316,7 @@ export function diff(
311316 if ( isHydrating || excessDomChildren != NULL ) {
312317 if ( e . then ) {
313318 let commentMarkersToFind = 0 ,
314- done = false ;
319+ done ;
315320
316321 newVNode . _flags |= isHydrating
317322 ? MODE_HYDRATE | MODE_SUSPENDED
@@ -329,21 +334,22 @@ export function diff(
329334 // We exclude the open and closing marker from
330335 // the future excessDomChildren but any nested one
331336 // needs to be included for future suspensions.
332- if ( child . nodeType == 8 && child . data == '$s' ) {
333- if ( commentMarkersToFind > 0 ) {
334- newVNode . _component . _excess . push ( child ) ;
335- }
336- commentMarkersToFind ++ ;
337- excessDomChildren [ i ] = NULL ;
338- } else if ( child . nodeType == 8 && child . data == '/$s' ) {
339- commentMarkersToFind -- ;
340- if ( commentMarkersToFind > 0 ) {
341- newVNode . _component . _excess . push ( child ) ;
337+ if ( child . nodeType == 8 ) {
338+ if ( child . data == '$s' ) {
339+ if ( commentMarkersToFind ) {
340+ newVNode . _component . _excess . push ( child ) ;
341+ }
342+ commentMarkersToFind ++ ;
343+ } else if ( child . data == '/$s' ) {
344+ commentMarkersToFind -- ;
345+ if ( commentMarkersToFind ) {
346+ newVNode . _component . _excess . push ( child ) ;
347+ }
348+ done = commentMarkersToFind == 0 ;
349+ oldDom = excessDomChildren [ i ] ;
342350 }
343- done = commentMarkersToFind === 0 ;
344- oldDom = excessDomChildren [ i ] ;
345351 excessDomChildren [ i ] = NULL ;
346- } else if ( commentMarkersToFind > 0 ) {
352+ } else if ( commentMarkersToFind ) {
347353 newVNode . _component . _excess . push ( child ) ;
348354 excessDomChildren [ i ] = NULL ;
349355 }
@@ -662,13 +668,11 @@ function diffElementNodes(
662668export function applyRef ( ref , value , vnode ) {
663669 try {
664670 if ( typeof ref == 'function' ) {
665- let hasRefUnmount = typeof ref . _unmount == 'function' ;
666- if ( hasRefUnmount ) {
667- // @ts -ignore TS doesn't like moving narrowing checks into variables
671+ if ( typeof ref . _unmount == 'function' ) {
668672 ref . _unmount ( ) ;
669673 }
670674
671- if ( ! hasRefUnmount || value != NULL ) {
675+ if ( typeof ref . _unmount != 'function' || value != NULL ) {
672676 // Store the cleanup function on the function
673677 // instance object itself to avoid shape
674678 // transitioning vnode
@@ -691,10 +695,8 @@ export function unmount(vnode, parentVNode, skipRemove) {
691695 let r ;
692696 if ( options . unmount ) options . unmount ( vnode ) ;
693697
694- if ( ( r = vnode . ref ) ) {
695- if ( ! r . current || r . current == vnode . _dom ) {
696- applyRef ( r , NULL , parentVNode ) ;
697- }
698+ if ( ( r = vnode . ref ) && ( ! r . current || r . current == vnode . _dom ) ) {
699+ applyRef ( r , NULL , parentVNode ) ;
698700 }
699701
700702 if ( ( r = vnode . _component ) != NULL ) {
0 commit comments