1- import { Component , createElement , options , Fragment } from 'preact' ;
1+ import { Component , Fragment , createElement , options } from 'preact' ;
22import {
3- MODE_HYDRATE ,
3+ COMPONENT_FORCE ,
44 FORCE_PROPS_REVALIDATE ,
5- COMPONENT_FORCE
5+ MODE_HYDRATE
66} from '../../src/constants' ;
77import { assign } from './util' ;
88
99const oldCatchError = options . _catchError ;
10- options . _catchError = function ( error , newVNode , oldVNode , errorInfo ) {
10+ options . _catchError = ( error , newVNode , oldVNode , errorInfo ) => {
1111 if ( error . then ) {
1212 /** @type {import('./internal').Component } */
1313 let component ;
1414 let vnode = newVNode ;
1515
16- for ( ; ( vnode = vnode . _parent ) ; ) {
16+ while ( ( vnode = vnode . _parent ) ) {
1717 if ( ( component = vnode . _component ) && component . _childDidSuspend ) {
1818 if ( newVNode . _dom == null ) {
1919 newVNode . _dom = oldVNode . _dom ;
@@ -28,7 +28,7 @@ options._catchError = function (error, newVNode, oldVNode, errorInfo) {
2828} ;
2929
3030const oldUnmount = options . unmount ;
31- options . unmount = function ( vnode ) {
31+ options . unmount = vnode => {
3232 /** @type {import('./internal').Component } */
3333 const component = vnode . _component ;
3434 if ( component ) component . _unmounted = true ;
@@ -118,17 +118,14 @@ Suspense.prototype = new Component();
118118Suspense . prototype . _childDidSuspend = function ( promise , suspendingVNode ) {
119119 const suspendingComponent = suspendingVNode . _component ;
120120
121- /** @type {import('./internal').SuspenseComponent } */
122- const c = this ;
123-
124- if ( c . _suspenders == null ) {
125- c . _suspenders = [ ] ;
121+ if ( this . _suspenders == null ) {
122+ this . _suspenders = [ ] ;
126123 }
127- c . _suspenders . push ( suspendingComponent ) ;
124+ this . _suspenders . push ( suspendingComponent ) ;
128125
129126 let resolved = false ;
130127 const onResolved = ( ) => {
131- if ( resolved || c . _unmounted ) return ;
128+ if ( resolved || this . _unmounted ) return ;
132129
133130 resolved = true ;
134131 suspendingComponent . _onResolve = null ;
@@ -145,22 +142,22 @@ Suspense.prototype._childDidSuspend = function (promise, suspendingVNode) {
145142 suspendingComponent . _parentDom = null ;
146143
147144 const onSuspensionComplete = ( ) => {
148- if ( ! -- c . _pendingSuspensionCount ) {
145+ if ( ! -- this . _pendingSuspensionCount ) {
149146 // If the suspension was during hydration we don't need to restore the
150147 // suspended children into the _children array
151- if ( c . state . _suspended ) {
152- const suspendedVNode = c . state . _suspended ;
153- c . _vnode . _children [ 0 ] = removeOriginal (
148+ if ( this . state . _suspended ) {
149+ const suspendedVNode = this . state . _suspended ;
150+ this . _vnode . _children [ 0 ] = removeOriginal (
154151 suspendedVNode ,
155152 suspendedVNode . _component . _parentDom ,
156153 suspendedVNode . _component . _originalParentDom
157154 ) ;
158155 }
159156
160- c . setState ( { _suspended : ( c . _detachOnNextRender = null ) } ) ;
157+ this . setState ( { _suspended : ( this . _detachOnNextRender = null ) } ) ;
161158
162159 let suspended ;
163- while ( ( suspended = c . _suspenders . pop ( ) ) ) {
160+ while ( ( suspended = this . _suspenders . pop ( ) ) ) {
164161 // Restore _parentDom before forceUpdate so render can proceed
165162 suspended . _parentDom = originalParentDom ;
166163 suspended . forceUpdate ( ) ;
@@ -174,10 +171,12 @@ Suspense.prototype._childDidSuspend = function (promise, suspendingVNode) {
174171 * While in non-hydration cases the usual fallback -> component flow would occour.
175172 */
176173 if (
177- ! c . _pendingSuspensionCount ++ &&
174+ ! this . _pendingSuspensionCount ++ &&
178175 ! ( suspendingVNode . _flags & MODE_HYDRATE )
179176 ) {
180- c . setState ( { _suspended : ( c . _detachOnNextRender = c . _vnode . _children [ 0 ] ) } ) ;
177+ this . setState ( {
178+ _suspended : ( this . _detachOnNextRender = this . _vnode . _children [ 0 ] )
179+ } ) ;
181180 }
182181 promise . then ( onResolved , onResolved ) ;
183182} ;
0 commit comments