317
);
318
},
319
320
- commitMount(
321
- domElement: Instance,
322
- type: string,
323
- newProps: Props,
324
- internalInstanceHandle: Object,
325
- ): void {
326
- ((domElement: any):
327
- | HTMLButtonElement
328
- | HTMLInputElement
329
- | HTMLSelectElement
330
- | HTMLTextAreaElement).focus();
331
- },
332
-
333
- commitUpdate(
334
- domElement: Instance,
335
- updatePayload: Array<mixed>,
336
- type: string,
337
- oldProps: Props,
338
- newProps: Props,
339
- internalInstanceHandle: Object,
340
- ): void {
341
- // Update the props handle so that we know which props are the ones with
342
- // with current event handlers.
343
- updateFiberProps(domElement, newProps);
344
- // Apply the diff to the DOM node.
345
- updateProperties(domElement, updatePayload, type, oldProps, newProps);
346
- },
347
-
320
shouldSetTextContent(type: string, props: Props): boolean {
321
return (
322
type === 'textarea' ||
328
);
329
},
330
359
- resetTextContent(domElement: Instance): void {
360
- domElement.textContent = '';
361
- },
362
-
331
shouldDeprioritizeSubtree(type: string, props: Props): boolean {
332
return !!props.hidden;
333
},
347
return textNode;
348
},
349
382
- commitTextUpdate(
383
- textInstance: TextInstance,
384
- oldText: string,
385
- newText: string,
386
- ): void {
387
- textInstance.nodeValue = newText;
388
- },
389
-
390
- appendChild(parentInstance: Instance, child: Instance | TextInstance): void {
391
- parentInstance.appendChild(child);
392
- },
393
-
394
- appendChildToContainer(
395
- container: Container,
396
- child: Instance | TextInstance,
397
- ): void {
398
- if (container.nodeType === COMMENT_NODE) {
399
- (container.parentNode: any).insertBefore(child, container);
400
- } else {
401
- container.appendChild(child);
402
- }
403
- },
404
-
405
- insertBefore(
406
- parentInstance: Instance,
407
- child: Instance | TextInstance,
408
- beforeChild: Instance | TextInstance,
409
- ): void {
410
- parentInstance.insertBefore(child, beforeChild);
411
- },
412
-
413
- insertInContainerBefore(
414
- container: Container,
415
- child: Instance | TextInstance,
416
- beforeChild: Instance | TextInstance,
417
- ): void {
418
- if (container.nodeType === COMMENT_NODE) {
419
- (container.parentNode: any).insertBefore(child, beforeChild);
420
- } else {
421
- container.insertBefore(child, beforeChild);
422
- }
423
- },
424
-
425
- removeChild(parentInstance: Instance, child: Instance | TextInstance): void {
426
- parentInstance.removeChild(child);
427
- },
428
-
429
- removeChildFromContainer(
430
- container: Container,
431
- child: Instance | TextInstance,
432
- ): void {
433
- if (container.nodeType === COMMENT_NODE) {
434
- (container.parentNode: any).removeChild(child);
435
- } else {
436
- container.removeChild(child);
437
- }
438
- },
439
-
350
now: ReactDOMFrameScheduling.now,
351
442
- canHydrateInstance(
443
- instance: Instance | TextInstance,
444
- type: string,
445
- props: Props,
446
- ): boolean {
447
- return (
448
- instance.nodeType === ELEMENT_NODE &&
449
- type.toLowerCase() === instance.nodeName.toLowerCase()
450
- );
451
- },
452
-
453
- canHydrateTextInstance(
454
- instance: Instance | TextInstance,
455
- text: string,
456
- ): boolean {
457
- if (text === '') {
458
- // Empty strings are not parsed by HTML so there won't be a correct match here.
459
- return false;
460
- }
461
- return instance.nodeType === TEXT_NODE;
462
- },
463
-
464
- getNextHydratableSibling(
465
- instance: Instance | TextInstance,
466
- ): null | Instance | TextInstance {
467
- let node = instance.nextSibling;
468
- // Skip non-hydratable nodes.
469
- while (
470
- node &&
471
- node.nodeType !== ELEMENT_NODE &&
472
- node.nodeType !== TEXT_NODE
352
+ mutation: {
353
+ commitMount(
354
+ domElement: Instance,
355
+ type: string,
356
+ newProps: Props,
357
+ internalInstanceHandle: Object,
358
+ ): void {
359
+ ((domElement: any):
360
+ | HTMLButtonElement
361
+ | HTMLInputElement
362
+ | HTMLSelectElement
363
+ | HTMLTextAreaElement).focus();
364
+ },
365
+
366
+ commitUpdate(
367
+ domElement: Instance,
368
+ updatePayload: Array<mixed>,
369
+ type: string,
370
+ oldProps: Props,
371
+ newProps: Props,
372
+ internalInstanceHandle: Object,
373
+ ): void {
374
+ // Update the props handle so that we know which props are the ones with
375
+ // with current event handlers.
376
+ updateFiberProps(domElement, newProps);
377
+ // Apply the diff to the DOM node.
378
+ updateProperties(domElement, updatePayload, type, oldProps, newProps);
379
+ },
380
+
381
+ resetTextContent(domElement: Instance): void {
382
+ domElement.textContent = '';
383
+ },
384
+
385
+ commitTextUpdate(
386
+ textInstance: TextInstance,
387
+ oldText: string,
388
+ newText: string,
389
+ ): void {
390
+ textInstance.nodeValue = newText;
391
+ },
392
+
393
+ appendChild(
394
+ parentInstance: Instance,
395
+ child: Instance | TextInstance,
396
+ ): void {
397
+ parentInstance.appendChild(child);
398
+ },
399
+
400
+ appendChildToContainer(
401
+ container: Container,
402
+ child: Instance | TextInstance,
403
+ ): void {
404
+ if (container.nodeType === COMMENT_NODE) {
405
+ (container.parentNode: any).insertBefore(child, container);
406
+ } else {
407
+ container.appendChild(child);
408
+ }
409
+ },
410
+
411
+ insertBefore(
412
+ parentInstance: Instance,
413
+ child: Instance | TextInstance,
414
+ beforeChild: Instance | TextInstance,
415
+ ): void {
416
+ parentInstance.insertBefore(child, beforeChild);
417
+ },
418
+
419
+ insertInContainerBefore(
420
+ container: Container,
421
+ child: Instance | TextInstance,
422
+ beforeChild: Instance | TextInstance,
423
+ ): void {
424
+ if (container.nodeType === COMMENT_NODE) {
425
+ (container.parentNode: any).insertBefore(child, beforeChild);
426
+ } else {
427
+ container.insertBefore(child, beforeChild);
428
+ }
429
+ },
430
+
431
+ removeChild(
432
+ parentInstance: Instance,
433
+ child: Instance | TextInstance,
434
+ ): void {
435
+ parentInstance.removeChild(child);
436
+ },
437
+
438
+ removeChildFromContainer(
439
+ container: Container,
440
+ child: Instance | TextInstance,
441
+ ): void {
442
+ if (container.nodeType === COMMENT_NODE) {
443
+ (container.parentNode: any).removeChild(child);
444
+ } else {
445
+ container.removeChild(child);
446
+ }
447
+ },
448
+ },
449
+
450
+ hydration: {
451
+ canHydrateInstance(
452
+ instance: Instance | TextInstance,
453
+ type: string,
454
+ props: Props,
455
+ ): boolean {
456
+ return (
457
+ instance.nodeType === ELEMENT_NODE &&
458
+ type.toLowerCase() === instance.nodeName.toLowerCase()
459
+ );
460
+ },
461
+
462
+ canHydrateTextInstance(
463
+ instance: Instance | TextInstance,
464
+ text: string,
465
+ ): boolean {
466
+ if (text === '') {
467
+ // Empty strings are not parsed by HTML so there won't be a correct match here.
468
+ return false;
469
+ }
470
+ return instance.nodeType === TEXT_NODE;
471
+ },
472
+
473
+ getNextHydratableSibling(
474
+ instance: Instance | TextInstance,
475
+ ): null | Instance | TextInstance {
476
+ let node = instance.nextSibling;
477
+ // Skip non-hydratable nodes.
478
+ while (
479
+ node &&
480
+ node.nodeType !== ELEMENT_NODE &&
481
+ node.nodeType !== TEXT_NODE
482
+ ) {
483
+ node = node.nextSibling;
484
+ }
485
+ return (node: any);
486
+ },
487
+
488
+ getFirstHydratableChild(
489
+ parentInstance: Container | Instance,
490
+ ): null | Instance | TextInstance {
491
+ let next = parentInstance.firstChild;
492
+ // Skip non-hydratable nodes.
493
+ while (
494
+ next &&
495
+ next.nodeType !== ELEMENT_NODE &&
496
+ next.nodeType !== TEXT_NODE
497
+ ) {
498
+ next = next.nextSibling;
499
+ }
500
+ return (next: any);
501
+ },
502
+
503
+ hydrateInstance(
504
+ instance: Instance,
505
+ type: string,
506
+ props: Props,
507
+ rootContainerInstance: Container,
508
+ hostContext: HostContext,
509
+ internalInstanceHandle: Object,
510
+ ): null | Array<mixed> {
511
+ precacheFiberNode(internalInstanceHandle, instance);
512
+ // TODO: Possibly defer this until the commit phase where all the events
513
+ // get attached.
514
+ updateFiberProps(instance, props);
515
+ let parentNamespace: string;
516
+ if (__DEV__) {
517
+ const hostContextDev = ((hostContext: any): HostContextDev);
518
+ parentNamespace = hostContextDev.namespace;
519
+ } else {
520
+ parentNamespace = ((hostContext: any): HostContextProd);
521
+ }
522
+ return diffHydratedProperties(
523
+ instance,
524
+ type,
525
+ props,
526
+ parentNamespace,
527
+ rootContainerInstance,
528
+ );
529
+ },
530
+
531
+ hydrateTextInstance(
532
+ textInstance: TextInstance,
533
+ text: string,
534
+ internalInstanceHandle: Object,
535
+ ): boolean {
536
+ precacheFiberNode(internalInstanceHandle, textInstance);
537
+ return diffHydratedText(textInstance, text);
538
+ },
539
+
540
+ didNotMatchHydratedContainerTextInstance(
541
+ parentContainer: Container,
542
+ textInstance: TextInstance,
543
+ text: string,
544
) {
474
- node = node.nextSibling;
475
- }
476
- return (node: any);
477
- },
478
-
479
- getFirstHydratableChild(
480
- parentInstance: Container | Instance,
481
- ): null | Instance | TextInstance {
482
- let next = parentInstance.firstChild;
483
- // Skip non-hydratable nodes.
484
- while (
485
- next &&
486
- next.nodeType !== ELEMENT_NODE &&
487
- next.nodeType !== TEXT_NODE
545
+ if (__DEV__) {
546
+ warnForUnmatchedText(textInstance, text);
547
+ }
548
+ },
549
+
550
+ didNotMatchHydratedTextInstance(
551
+ parentType: string,
552
+ parentProps: Props,
553
+ parentInstance: Instance,
554
+ textInstance: TextInstance,
555
+ text: string,
556
) {
489
- next = next.nextSibling;
490
- }
491
- return (next: any);
492
- },
493
-
494
- hydrateInstance(
495
- instance: Instance,
496
- type: string,
497
- props: Props,
498
- rootContainerInstance: Container,
499
- hostContext: HostContext,
500
- internalInstanceHandle: Object,
501
- ): null | Array<mixed> {
502
- precacheFiberNode(internalInstanceHandle, instance);
503
- // TODO: Possibly defer this until the commit phase where all the events
504
- // get attached.
505
- updateFiberProps(instance, props);
506
- let parentNamespace: string;
507
- if (__DEV__) {
508
- const hostContextDev = ((hostContext: any): HostContextDev);
509
- parentNamespace = hostContextDev.namespace;
510
- } else {
511
- parentNamespace = ((hostContext: any): HostContextProd);
512
- }
513
- return diffHydratedProperties(
514
- instance,
515
- type,
516
- props,
517
- parentNamespace,
518
- rootContainerInstance,
519
- );
520
- },
521
-
522
- hydrateTextInstance(
523
- textInstance: TextInstance,
524
- text: string,
525
- internalInstanceHandle: Object,
526
- ): boolean {
527
- precacheFiberNode(internalInstanceHandle, textInstance);
528
- return diffHydratedText(textInstance, text);
529
- },
530
-
531
- didNotMatchHydratedContainerTextInstance(
532
- parentContainer: Container,
533
- textInstance: TextInstance,
534
- text: string,
535
- ) {
536
- if (__DEV__) {
537
- warnForUnmatchedText(textInstance, text);
538
- }
539
- },
540
-
541
- didNotMatchHydratedTextInstance(
542
- parentType: string,
543
- parentProps: Props,
544
- parentInstance: Instance,
545
- textInstance: TextInstance,
546
- text: string,
547
- ) {
548
- if (__DEV__ && parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
549
- warnForUnmatchedText(textInstance, text);
550
- }
551
- },
552
-
553
- didNotHydrateContainerInstance(
554
- parentContainer: Container,
555
- instance: Instance | TextInstance,
556
- ) {
557
- if (__DEV__) {
558
- if (instance.nodeType === 1) {
559
- warnForDeletedHydratableElement(parentContainer, (instance: any));
560
- } else {
561
- warnForDeletedHydratableText(parentContainer, (instance: any));
557
+ if (__DEV__ && parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
558
+ warnForUnmatchedText(textInstance, text);
559
}
563
- }
564
- },
560
+ },
561
566
- didNotHydrateInstance(
567
- parentType: string,
568
- parentProps: Props,
569
- parentInstance: Instance,
570
- instance: Instance | TextInstance,
571
- ) {
572
- if (__DEV__ && parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
573
- if (instance.nodeType === 1) {
574
- warnForDeletedHydratableElement(parentInstance, (instance: any));
575
- } else {
576
- warnForDeletedHydratableText(parentInstance, (instance: any));
562
+ didNotHydrateContainerInstance(
563
+ parentContainer: Container,
564
+ instance: Instance | TextInstance,
565
+ ) {
566
+ if (__DEV__) {
567
+ if (instance.nodeType === 1) {
568
+ warnForDeletedHydratableElement(parentContainer, (instance: any));
569
+ } else {
570
+ warnForDeletedHydratableText(parentContainer, (instance: any));
571
+ }
572
}
578
- }
579
- },
573
+ },
574
581
- didNotFindHydratableContainerInstance(
582
- parentContainer: Container,
583
- type: string,
584
- props: Props,
585
- ) {
586
- if (__DEV__) {
587
- warnForInsertedHydratedElement(parentContainer, type, props);
588
- }
589
- },
575
+ didNotHydrateInstance(
576
+ parentType: string,
577
+ parentProps: Props,
578
+ parentInstance: Instance,
579
+ instance: Instance | TextInstance,
580
+ ) {
581
+ if (__DEV__ && parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
582
+ if (instance.nodeType === 1) {
583
+ warnForDeletedHydratableElement(parentInstance, (instance: any));
584
+ } else {
585
+ warnForDeletedHydratableText(parentInstance, (instance: any));
586
+ }
587
+ }
588
+ },
589
591
- didNotFindHydratableContainerTextInstance(
592
- parentContainer: Container,
593
- text: string,
594
- ) {
595
- if (__DEV__) {
596
- warnForInsertedHydratedText(parentContainer, text);
597
- }
598
- },
590
+ didNotFindHydratableContainerInstance(
591
+ parentContainer: Container,
592
+ type: string,
593
+ props: Props,
594
+ ) {
595
+ if (__DEV__) {
596
+ warnForInsertedHydratedElement(parentContainer, type, props);
597
+ }
598
+ },
599
600
- didNotFindHydratableInstance(
601
- parentType: string,
602
- parentProps: Props,
603
- parentInstance: Instance,
604
- type: string,
605
- props: Props,
606
- ) {
607
- if (__DEV__ && parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
608
- warnForInsertedHydratedElement(parentInstance, type, props);
609
- }
610
- },
600
+ didNotFindHydratableContainerTextInstance(
601
+ parentContainer: Container,
602
+ text: string,
603
+ ) {
604
+ if (__DEV__) {
605
+ warnForInsertedHydratedText(parentContainer, text);
606
+ }
607
+ },
608
+
609
+ didNotFindHydratableInstance(
610
+ parentType: string,
611
+ parentProps: Props,
612
+ parentInstance: Instance,
613
+ type: string,
614
+ props: Props,
615
+ ) {
616
+ if (__DEV__ && parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
617
+ warnForInsertedHydratedElement(parentInstance, type, props);
618
+ }
619
+ },
620
612
- didNotFindHydratableTextInstance(
613
- parentType: string,
614
- parentProps: Props,
615
- parentInstance: Instance,
616
- text: string,
617
- ) {
618
- if (__DEV__ && parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
619
- warnForInsertedHydratedText(parentInstance, text);
620
- }
621
+ didNotFindHydratableTextInstance(
622
+ parentType: string,
623
+ parentProps: Props,
624
+ parentInstance: Instance,
625
+ text: string,
626
+ ) {
627
+ if (__DEV__ && parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
628
+ warnForInsertedHydratedText(parentInstance, text);
629
+ }
630
+ },
631
},
632
633
scheduleDeferredCallback: ReactDOMFrameScheduling.rIC,