12
12
13
13
'use strict' ;
14
14
15
- import type { TrappedError } from 'ReactFiberScheduler' ;
16
15
import type { Fiber } from 'ReactFiber' ;
17
16
import type { FiberRoot } from 'ReactFiberRoot' ;
18
17
import type { HostConfig } from 'ReactFiberReconciler' ;
34
33
35
34
module . exports = function < T , P , I , TI , C > (
36
35
config : HostConfig < T , P , I , TI , C > ,
37
- trapError : ( boundary : Fiber , error : Error ) = > TrappedError
36
+ trapError : ( fiber : Fiber , error : Error , isUnmounting : boolean ) = > void
38
37
) {
39
38
40
39
const updateContainer = config . updateContainer ;
@@ -158,94 +157,71 @@ module.exports = function<T, P, I, TI, C>(
158
157
}
159
158
}
160
159
161
- function commitNestedUnmounts ( root : Fiber ) : Array < TrappedError > | null {
162
- // Since errors are rare, we allocate this array on demand.
163
- let trappedErrors = null ;
164
-
160
+ function commitNestedUnmounts ( root : Fiber ) : void {
165
161
// While we're inside a removed host node we don't want to call
166
162
// removeChild on the inner nodes because they're removed by the top
167
163
// call anyway. We also want to call componentWillUnmount on all
168
164
// composites before this host node is removed from the tree. Therefore
169
165
// we do an inner loop while we're still inside the host node.
170
166
let node : Fiber = root ;
171
167
while ( true ) {
172
- const error = commitUnmount ( node ) ;
173
- if ( error ) {
174
- trappedErrors = trappedErrors || [ ] ;
175
- trappedErrors . push ( error ) ;
176
- }
168
+ commitUnmount ( node ) ;
177
169
if ( node . child ) {
178
170
// TODO: Coroutines need to visit the stateNode.
179
171
node = node . child ;
180
172
continue ;
181
173
}
182
174
if ( node === root ) {
183
- return trappedErrors ;
175
+ return ;
184
176
}
185
177
while ( ! node . sibling ) {
186
178
if ( ! node . return || node . return === root ) {
187
- return trappedErrors ;
179
+ return ;
188
180
}
189
181
node = node . return ;
190
182
}
191
183
node = node . sibling ;
192
184
}
193
- return trappedErrors ;
194
185
}
195
186
196
- function unmountHostComponents ( parent , current ) : Array < TrappedError > | null {
197
- // Since errors are rare, we allocate this array on demand.
198
- let trappedErrors = null ;
199
-
187
+ function unmountHostComponents ( parent , current ) : void {
200
188
// We only have the top Fiber that was inserted but we need recurse down its
201
189
// children to find all the terminal nodes.
202
190
let node : Fiber = current ;
203
191
while ( true ) {
204
192
if ( node . tag === HostComponent || node . tag === HostText ) {
205
- const errors = commitNestedUnmounts ( node ) ;
206
- if ( errors ) {
207
- if ( ! trappedErrors ) {
208
- trappedErrors = errors ;
209
- } else {
210
- trappedErrors . push . apply ( trappedErrors , errors ) ;
211
- }
212
- }
193
+ commitNestedUnmounts ( node ) ;
213
194
// After all the children have unmounted, it is now safe to remove the
214
195
// node from the tree.
215
196
if ( parent ) {
216
197
removeChild ( parent , node . stateNode ) ;
217
198
}
218
199
} else {
219
- const error = commitUnmount ( node ) ;
220
- if ( error ) {
221
- trappedErrors = trappedErrors || [ ] ;
222
- trappedErrors . push ( error ) ;
223
- }
200
+ commitUnmount ( node ) ;
224
201
if ( node . child ) {
225
202
// TODO: Coroutines need to visit the stateNode.
226
203
node = node . child ;
227
204
continue ;
228
205
}
229
206
}
230
207
if ( node === current ) {
231
- return trappedErrors ;
208
+ return ;
232
209
}
233
210
while ( ! node . sibling ) {
234
211
if ( ! node . return || node . return === current ) {
235
- return trappedErrors ;
212
+ return ;
236
213
}
237
214
node = node . return ;
238
215
}
239
216
node = node . sibling ;
240
217
}
241
- return trappedErrors ;
242
218
}
243
219
244
- function commitDeletion ( current : Fiber ) : Array < TrappedError > | null {
220
+ function commitDeletion ( current : Fiber ) : void {
245
221
// Recursively delete all host nodes from the parent.
246
222
const parent = getHostParent ( current ) ;
247
223
// Detach refs and call componentWillUnmount() on the whole subtree.
248
- const trappedErrors = unmountHostComponents ( parent , current ) ;
224
+ unmountHostComponents ( parent , current ) ;
249
225
250
226
// Cut off the return pointers to disconnect it from the tree. Ideally, we
251
227
// should clear the child pointer of the parent alternate to let this
@@ -258,29 +234,24 @@ module.exports = function<T, P, I, TI, C>(
258
234
current . alternate . child = null ;
259
235
current . alternate . return = null ;
260
236
}
261
-
262
- return trappedErrors ;
263
237
}
264
238
265
- function commitUnmount ( current : Fiber ) : TrappedError | null {
239
+ function commitUnmount ( current : Fiber ) : void {
266
240
switch ( current . tag ) {
267
241
case ClassComponent : {
268
242
detachRef ( current ) ;
269
243
const instance = current . stateNode ;
270
244
if ( typeof instance . componentWillUnmount === 'function' ) {
271
245
const error = tryCallComponentWillUnmount ( instance ) ;
272
246
if ( error ) {
273
- return trapError ( current , error ) ;
247
+ trapError ( current , error , true ) ;
274
248
}
275
249
}
276
- return null ;
250
+ return ;
277
251
}
278
252
case HostComponent : {
279
253
detachRef ( current ) ;
280
- return null ;
281
- }
282
- default : {
283
- return null ;
254
+ return ;
284
255
}
285
256
}
286
257
}
@@ -325,7 +296,7 @@ module.exports = function<T, P, I, TI, C>(
325
296
}
326
297
}
327
298
328
- function commitLifeCycles ( current : ?Fiber , finishedWork : Fiber ) : TrappedError | null {
299
+ function commitLifeCycles ( current : ?Fiber , finishedWork : Fiber ) : void {
329
300
switch ( finishedWork . tag ) {
330
301
case ClassComponent : {
331
302
const instance = finishedWork . stateNode ;
@@ -355,9 +326,9 @@ module.exports = function<T, P, I, TI, C>(
355
326
}
356
327
}
357
328
if ( error ) {
358
- return trapError ( finishedWork , error ) ;
329
+ trapError ( finishedWork , error , false ) ;
359
330
}
360
- return null ;
331
+ return ;
361
332
}
362
333
case HostContainer : {
363
334
const rootFiber = finishedWork . stateNode ;
@@ -366,15 +337,16 @@ module.exports = function<T, P, I, TI, C>(
366
337
rootFiber . callbackList = null ;
367
338
callCallbacks ( callbackList , rootFiber . current . child . stateNode ) ;
368
339
}
340
+ return ;
369
341
}
370
342
case HostComponent : {
371
343
const instance : I = finishedWork . stateNode ;
372
344
attachRef ( current , finishedWork , instance ) ;
373
- return null ;
345
+ return ;
374
346
}
375
347
case HostText : {
376
348
// We have no life-cycles associated with text.
377
- return null ;
349
+ return ;
378
350
}
379
351
default :
380
352
throw new Error ( 'This unit of work tag should not have side-effects.' ) ;
0 commit comments