20
20
import type { Fiber } from 'ReactFiber' ;
21
21
import type { UpdateQueue } from 'ReactFiberUpdateQueue' ;
22
22
23
+ var ReactFeatureFlags = require ( 'ReactFeatureFlags' ) ;
23
24
var ReactFiberInstrumentation = require ( 'ReactFiberInstrumentation' ) ;
24
25
var ReactFiberReconciler = require ( 'ReactFiberReconciler' ) ;
25
26
var ReactInstanceMap = require ( 'ReactInstanceMap' ) ;
@@ -178,105 +179,94 @@ var SharedHostConfig = {
178
179
} ,
179
180
} ;
180
181
181
- var MutationHostConfig = {
182
- commitMount ( instance : Instance , type : string , newProps : Props ) : void {
183
- // Noop
184
- } ,
185
-
186
- commitUpdate (
187
- instance : Instance ,
188
- updatePayload : Object ,
189
- type : string ,
190
- oldProps : Props ,
191
- newProps : Props ,
192
- ) : void {
193
- instance . prop = newProps . prop;
194
- } ,
195
-
196
- commitTextUpdate (
197
- textInstance : TextInstance ,
198
- oldText : string ,
199
- newText : string ,
200
- ) : void {
201
- textInstance . text = newText ;
202
- } ,
203
-
204
- appendChild: appendChild ,
205
- appendChildToContainer : appendChild ,
206
- insertBefore : insertBefore ,
207
- insertInContainerBefore : insertBefore ,
208
- removeChild : removeChild ,
209
- removeChildFromContainer : removeChild ,
210
-
211
- resetTextContent ( instance : Instance ) : void { } ,
212
- } ;
213
-
214
- var PersistenceHostConfig = {
215
- cloneInstance (
216
- instance : Instance ,
217
- updatePayload : null | Object ,
218
- type : string ,
219
- oldProps : Props ,
220
- newProps : Props ,
221
- internalInstanceHandle : Object ,
222
- keepChildren : boolean ,
223
- recyclableInstance : null | Instance ,
224
- ) : Instance {
225
- const clone = {
226
- id : instance . id ,
227
- type : type ,
228
- children : keepChildren ? instance . children : [ ] ,
229
- prop : newProps . prop ,
230
- } ;
231
- Object . defineProperty ( clone , 'id' , {
232
- value : clone . id ,
233
- enumerable : false ,
234
- } ) ;
235
- return clone ;
236
- } ,
237
-
238
- cloneContainer (
239
- container : Container ,
240
- recyclableContainer : Container ,
241
- ) : Container {
242
- return { rootID : container . rootID , children : [ ] } ;
243
- } ,
244
-
245
- appendInititalChildToContainer (
246
- parentInstance : Container ,
247
- child : Instance | TextInstance ,
248
- ) {
249
- parentInstance . children . push ( child ) ;
250
- } ,
251
-
252
- finalizeContainerChildren ( container : Container ) : void { } ,
253
-
254
- replaceContainer ( oldContainer : Container , newContainer : Container ) : void {
255
- rootContainers. set ( oldContainer . rootID , newContainer ) ;
256
- } ,
257
- } ;
258
-
259
- // They are created lazily because only one can be created per test file.
260
- var renderer = null ;
261
- var persistentRenderer = null ;
262
- function getRenderer ( ) {
263
- return (
264
- renderer ||
265
- ( renderer = ReactFiberReconciler ( {
182
+ var NoopRenderer = ReactFiberReconciler ( {
183
+ ...SharedHostConfig ,
184
+ mutation : {
185
+ commitMount ( instance : Instance , type : string , newProps : Props ) : void {
186
+ // Noop
187
+ } ,
188
+
189
+ commitUpdate (
190
+ instance : Instance ,
191
+ updatePayload : Object ,
192
+ type : string ,
193
+ oldProps : Props ,
194
+ newProps : Props ,
195
+ ) : void {
196
+ instance . prop = newProps . prop;
197
+ } ,
198
+
199
+ commitTextUpdate (
200
+ textInstance : TextInstance ,
201
+ oldText : string ,
202
+ newText : string ,
203
+ ) : void {
204
+ textInstance . text = newText;
205
+ } ,
206
+
207
+ appendChild : appendChild ,
208
+ appendChildToContainer : appendChild ,
209
+ insertBefore : insertBefore ,
210
+ insertInContainerBefore : insertBefore ,
211
+ removeChild : removeChild ,
212
+ removeChildFromContainer : removeChild ,
213
+
214
+ resetTextContent ( instance : Instance ) : void { } ,
215
+ } ,
216
+ } ) ;
217
+
218
+ var PersistentNoopRenderer = ReactFeatureFlags . enablePersistentReconciler
219
+ ? ReactFiberReconciler ( {
266
220
...SharedHostConfig ,
267
- mutation : MutationHostConfig ,
268
- } ) )
269
- ) ;
270
- }
271
- function getPersistentRenderer ( ) {
272
- return (
273
- persistentRenderer ||
274
- ( persistentRenderer = ReactFiberReconciler ( {
275
- ...SharedHostConfig ,
276
- persistence : PersistenceHostConfig ,
277
- } ) )
278
- ) ;
279
- }
221
+ persistence : {
222
+ cloneInstance (
223
+ instance : Instance ,
224
+ updatePayload : null | Object ,
225
+ type : string ,
226
+ oldProps : Props ,
227
+ newProps : Props ,
228
+ internalInstanceHandle : Object ,
229
+ keepChildren : boolean ,
230
+ recyclableInstance : null | Instance ,
231
+ ) : Instance {
232
+ const clone = {
233
+ id : instance . id ,
234
+ type : type ,
235
+ children : keepChildren ? instance . children : [ ] ,
236
+ prop : newProps . prop ,
237
+ } ;
238
+ Object . defineProperty ( clone , 'id' , {
239
+ value : clone . id ,
240
+ enumerable : false ,
241
+ } ) ;
242
+ return clone ;
243
+ } ,
244
+
245
+ cloneContainer (
246
+ container : Container ,
247
+ recyclableContainer : Container ,
248
+ ) : Container {
249
+ return { rootID : container . rootID , children : [ ] } ;
250
+ } ,
251
+
252
+ appendInititalChildToContainer (
253
+ parentInstance : Container ,
254
+ child : Instance | TextInstance ,
255
+ ) {
256
+ parentInstance . children . push ( child ) ;
257
+ } ,
258
+
259
+ finalizeContainerChildren ( container : Container ) : void { } ,
260
+
261
+ replaceContainer (
262
+ oldContainer : Container ,
263
+ newContainer : Container ,
264
+ ) : void {
265
+ rootContainers . set ( oldContainer . rootID , newContainer ) ;
266
+ } ,
267
+ } ,
268
+ } )
269
+ : null ;
280
270
281
271
var rootContainers = new Map ( ) ;
282
272
var roots = new Map ( ) ;
@@ -333,7 +323,6 @@ var ReactNoop = {
333
323
rootID : string ,
334
324
callback : ?Function ,
335
325
) {
336
- const NoopRenderer = getRenderer ( ) ;
337
326
let root = roots . get ( rootID ) ;
338
327
if ( ! root ) {
339
328
const container = { rootID : rootID , children : [ ] } ;
@@ -349,7 +338,11 @@ var ReactNoop = {
349
338
rootID : string ,
350
339
callback : ?Function ,
351
340
) {
352
- const PersistentNoopRenderer = getPersistentRenderer ( ) ;
341
+ if ( PersistentNoopRenderer === null ) {
342
+ throw new Error (
343
+ 'Enable ReactFeatureFlags.enablePersistentReconciler to use it in tests.' ,
344
+ ) ;
345
+ }
353
346
let root = persistentRoots . get ( rootID ) ;
354
347
if ( ! root ) {
355
348
const container = { rootID : rootID , children : [ ] } ;
@@ -361,7 +354,6 @@ var ReactNoop = {
361
354
} ,
362
355
363
356
unmountRootWithID ( rootID : string ) {
364
- const NoopRenderer = getRenderer ( ) ;
365
357
const root = roots . get ( rootID ) ;
366
358
if ( root ) {
367
359
NoopRenderer . updateContainer ( null , root , null , ( ) => {
@@ -374,7 +366,6 @@ var ReactNoop = {
374
366
findInstance (
375
367
componentOrElement : Element | ?React$Component < any , any > ,
376
368
) : null | Instance | TextInstance {
377
- const NoopRenderer = getRenderer ( ) ;
378
369
if ( componentOrElement == null ) {
379
370
return null ;
380
371
}
@@ -451,25 +442,13 @@ var ReactNoop = {
451
442
return ! ! scheduledCallback ;
452
443
} ,
453
444
454
- batchedUpdates ( ...args : Array < any > ) {
455
- const NoopRenderer = getRenderer ( ) ;
456
- return NoopRenderer . batchedUpdates ( ...args ) ;
457
- } ,
445
+ batchedUpdates : NoopRenderer . batchedUpdates ,
458
446
459
- deferredUpdates ( ...args : Array < any > ) {
460
- const NoopRenderer = getRenderer ( ) ;
461
- return NoopRenderer . deferredUpdates ( ...args ) ;
462
- } ,
447
+ deferredUpdates : NoopRenderer . deferredUpdates ,
463
448
464
- unbatchedUpdates ( ...args : Array < any > ) {
465
- const NoopRenderer = getRenderer ( ) ;
466
- return NoopRenderer . unbatchedUpdates ( ...args ) ;
467
- } ,
449
+ unbatchedUpdates : NoopRenderer . unbatchedUpdates ,
468
450
469
- flushSync ( ...args : Array < any > ) {
470
- const NoopRenderer = getRenderer ( ) ;
471
- return NoopRenderer . flushSync ( ...args ) ;
472
- } ,
451
+ flushSync : NoopRenderer . flushSync ,
473
452
474
453
// Logs the current state of the tree.
475
454
dumpTree ( rootID : string = DEFAULT_ROOT_ID ) {
0 commit comments