GeezerVison is showing github.com — Re-add old Fabric Offscreen impl behind flag (#22018) · react/react@19092ac
File treeExpand file treeCollapse file tree Open diff view settings react-native-renderer/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactFabricHostConfig.js +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -460,6 +460,32 @@ export function getOffscreenContainerProps( | 460 | 460 | } | 461 | 461 | } | 462 | 462 |
| | 463 | +export function cloneHiddenInstance( | | 464 | + instance: Instance, | | 465 | + type: string, | | 466 | + props: Props, | | 467 | + internalInstanceHandle: Object, | | 468 | +): Instance { | | 469 | + const viewConfig = instance.canonical.viewConfig; | | 470 | + const node = instance.node; | | 471 | + const updatePayload = create( | | 472 | + {style: {display: 'none'}}, | | 473 | + viewConfig.validAttributes, | | 474 | + ); | | 475 | + return { | | 476 | + node: cloneNodeWithNewProps(node, updatePayload), | | 477 | + canonical: instance.canonical, | | 478 | + }; | | 479 | +} | | 480 | + | | 481 | +export function cloneHiddenTextInstance( | | 482 | + instance: Instance, | | 483 | + text: string, | | 484 | + internalInstanceHandle: Object, | | 485 | +): TextInstance { | | 486 | + throw new Error('Not yet implemented.'); | | 487 | +} | | 488 | + | 463 | 489 | export function createContainerChildSet(container: Container): ChildSet { | 464 | 490 | return createChildNodeSet(container); | 465 | 491 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-noop-renderer/src/createReactNoop.js +48Lines changed: 48 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -582,6 +582,54 @@ function createReactNoop(reconciler: Function, useMutation: boolean) { | 582 | 582 | children, | 583 | 583 | }; | 584 | 584 | }, | | 585 | + | | 586 | + cloneHiddenInstance( | | 587 | + instance: Instance, | | 588 | + type: string, | | 589 | + props: Props, | | 590 | + internalInstanceHandle: Object, | | 591 | + ): Instance { | | 592 | + const clone = cloneInstance( | | 593 | + instance, | | 594 | + null, | | 595 | + type, | | 596 | + props, | | 597 | + props, | | 598 | + internalInstanceHandle, | | 599 | + true, | | 600 | + null, | | 601 | + ); | | 602 | + clone.hidden = true; | | 603 | + return clone; | | 604 | + }, | | 605 | + | | 606 | + cloneHiddenTextInstance( | | 607 | + instance: TextInstance, | | 608 | + text: string, | | 609 | + internalInstanceHandle: Object, | | 610 | + ): TextInstance { | | 611 | + const clone = { | | 612 | + text: instance.text, | | 613 | + id: instance.id, | | 614 | + parent: instance.parent, | | 615 | + hidden: true, | | 616 | + context: instance.context, | | 617 | + }; | | 618 | + // Hide from unit tests | | 619 | + Object.defineProperty(clone, 'id', { | | 620 | + value: clone.id, | | 621 | + enumerable: false, | | 622 | + }); | | 623 | + Object.defineProperty(clone, 'parent', { | | 624 | + value: clone.parent, | | 625 | + enumerable: false, | | 626 | + }); | | 627 | + Object.defineProperty(clone, 'context', { | | 628 | + value: clone.context, | | 629 | + enumerable: false, | | 630 | + }); | | 631 | + return clone; | | 632 | + }, | 585 | 633 | }; | 586 | 634 |
| 587 | 635 | const NoopRenderer = reconciler(hostConfig); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.new.js +5-7Lines changed: 5 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -89,6 +89,7 @@ import { | 89 | 89 | enableLazyContextPropagation, | 90 | 90 | enableSuspenseLayoutEffectSemantics, | 91 | 91 | enableSchedulingProfiler, | | 92 | + enablePersistentOffscreenHostContainer, | 92 | 93 | } from 'shared/ReactFeatureFlags'; | 93 | 94 | import invariant from 'shared/invariant'; | 94 | 95 | import isArray from 'shared/isArray'; | @@ -146,7 +147,6 @@ import { | 146 | 147 | registerSuspenseInstanceRetry, | 147 | 148 | supportsHydration, | 148 | 149 | isPrimaryRenderer, | 149 | | - supportsMutation, | 150 | 150 | supportsPersistence, | 151 | 151 | getOffscreenContainerProps, | 152 | 152 | } from './ReactFiberHostConfig'; | @@ -744,7 +744,7 @@ function updateOffscreenComponent( | 744 | 744 | workInProgress.updateQueue = spawnedCachePool; | 745 | 745 | } | 746 | 746 |
| 747 | | - if (supportsPersistence) { | | 747 | + if (enablePersistentOffscreenHostContainer && supportsPersistence) { | 748 | 748 | // In persistent mode, the offscreen children are wrapped in a host node. | 749 | 749 | // TODO: Optimize this to use the OffscreenComponent fiber instead of | 750 | 750 | // an extra HostComponent fiber. Need to make sure this doesn't break Fabric | @@ -760,12 +760,10 @@ function updateOffscreenComponent( | 760 | 760 | renderLanes, | 761 | 761 | ); | 762 | 762 | return offscreenContainer; | 763 | | - } | 764 | | - if (supportsMutation) { | | 763 | + } else { | 765 | 764 | reconcileChildren(current, workInProgress, nextChildren, renderLanes); | 766 | 765 | return workInProgress.child; | 767 | 766 | } | 768 | | - return null; | 769 | 767 | } | 770 | 768 |
| 771 | 769 | function reconcileOffscreenHostContainer( | @@ -2383,7 +2381,7 @@ function updateSuspenseFallbackChildren( | 2383 | 2381 | currentPrimaryChildFragment.treeBaseDuration; | 2384 | 2382 | } | 2385 | 2383 |
| 2386 | | - if (supportsPersistence) { | | 2384 | + if (enablePersistentOffscreenHostContainer && supportsPersistence) { | 2387 | 2385 | // In persistent mode, the offscreen children are wrapped in a host node. | 2388 | 2386 | // We need to complete it now, because we're going to skip over its normal | 2389 | 2387 | // complete phase and go straight to rendering the fallback. | @@ -2411,7 +2409,7 @@ function updateSuspenseFallbackChildren( | 2411 | 2409 | primaryChildProps, | 2412 | 2410 | ); | 2413 | 2411 |
| 2414 | | - if (supportsPersistence) { | | 2412 | + if (enablePersistentOffscreenHostContainer && supportsPersistence) { | 2415 | 2413 | // In persistent mode, the offscreen children are wrapped in a host node. | 2416 | 2414 | // We need to complete it now, because we're going to skip over its normal | 2417 | 2415 | // complete phase and go straight to rendering the fallback. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.old.js +5-7Lines changed: 5 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -89,6 +89,7 @@ import { | 89 | 89 | enableLazyContextPropagation, | 90 | 90 | enableSuspenseLayoutEffectSemantics, | 91 | 91 | enableSchedulingProfiler, | | 92 | + enablePersistentOffscreenHostContainer, | 92 | 93 | } from 'shared/ReactFeatureFlags'; | 93 | 94 | import invariant from 'shared/invariant'; | 94 | 95 | import isArray from 'shared/isArray'; | @@ -146,7 +147,6 @@ import { | 146 | 147 | registerSuspenseInstanceRetry, | 147 | 148 | supportsHydration, | 148 | 149 | isPrimaryRenderer, | 149 | | - supportsMutation, | 150 | 150 | supportsPersistence, | 151 | 151 | getOffscreenContainerProps, | 152 | 152 | } from './ReactFiberHostConfig'; | @@ -744,7 +744,7 @@ function updateOffscreenComponent( | 744 | 744 | workInProgress.updateQueue = spawnedCachePool; | 745 | 745 | } | 746 | 746 |
| 747 | | - if (supportsPersistence) { | | 747 | + if (enablePersistentOffscreenHostContainer && supportsPersistence) { | 748 | 748 | // In persistent mode, the offscreen children are wrapped in a host node. | 749 | 749 | // TODO: Optimize this to use the OffscreenComponent fiber instead of | 750 | 750 | // an extra HostComponent fiber. Need to make sure this doesn't break Fabric | @@ -760,12 +760,10 @@ function updateOffscreenComponent( | 760 | 760 | renderLanes, | 761 | 761 | ); | 762 | 762 | return offscreenContainer; | 763 | | - } | 764 | | - if (supportsMutation) { | | 763 | + } else { | 765 | 764 | reconcileChildren(current, workInProgress, nextChildren, renderLanes); | 766 | 765 | return workInProgress.child; | 767 | 766 | } | 768 | | - return null; | 769 | 767 | } | 770 | 768 |
| 771 | 769 | function reconcileOffscreenHostContainer( | @@ -2383,7 +2381,7 @@ function updateSuspenseFallbackChildren( | 2383 | 2381 | currentPrimaryChildFragment.treeBaseDuration; | 2384 | 2382 | } | 2385 | 2383 |
| 2386 | | - if (supportsPersistence) { | | 2384 | + if (enablePersistentOffscreenHostContainer && supportsPersistence) { | 2387 | 2385 | // In persistent mode, the offscreen children are wrapped in a host node. | 2388 | 2386 | // We need to complete it now, because we're going to skip over its normal | 2389 | 2387 | // complete phase and go straight to rendering the fallback. | @@ -2411,7 +2409,7 @@ function updateSuspenseFallbackChildren( | 2411 | 2409 | primaryChildProps, | 2412 | 2410 | ); | 2413 | 2411 |
| 2414 | | - if (supportsPersistence) { | | 2412 | + if (enablePersistentOffscreenHostContainer && supportsPersistence) { | 2415 | 2413 | // In persistent mode, the offscreen children are wrapped in a host node. | 2416 | 2414 | // We need to complete it now, because we're going to skip over its normal | 2417 | 2415 | // complete phase and go straight to rendering the fallback. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCompleteWork.new.js +77-10Lines changed: 77 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -84,6 +84,8 @@ import { | 84 | 84 | supportsMutation, | 85 | 85 | supportsPersistence, | 86 | 86 | cloneInstance, | | 87 | + cloneHiddenInstance, | | 88 | + cloneHiddenTextInstance, | 87 | 89 | createContainerChildSet, | 88 | 90 | appendChildToContainerChildSet, | 89 | 91 | finalizeContainerChildren, | @@ -128,6 +130,7 @@ import { | 128 | 130 | enableProfilerTimer, | 129 | 131 | enableCache, | 130 | 132 | enableSuspenseLayoutEffectSemantics, | | 133 | + enablePersistentOffscreenHostContainer, | 131 | 134 | } from 'shared/ReactFeatureFlags'; | 132 | 135 | import { | 133 | 136 | renderDidSuspend, | @@ -198,7 +201,12 @@ let updateHostText; | 198 | 201 | if (supportsMutation) { | 199 | 202 | // Mutation mode | 200 | 203 |
| 201 | | - appendAllChildren = function(parent: Instance, workInProgress: Fiber) { | | 204 | + appendAllChildren = function( | | 205 | + parent: Instance, | | 206 | + workInProgress: Fiber, | | 207 | + needsVisibilityToggle: boolean, | | 208 | + isHidden: boolean, | | 209 | + ) { | 202 | 210 | // We only have the top Fiber that was created but we need recurse down its | 203 | 211 | // children to find all the terminal nodes. | 204 | 212 | let node = workInProgress.child; | @@ -286,22 +294,53 @@ if (supportsMutation) { | 286 | 294 | } else if (supportsPersistence) { | 287 | 295 | // Persistent host tree mode | 288 | 296 |
| 289 | | - appendAllChildren = function(parent: Instance, workInProgress: Fiber) { | | 297 | + appendAllChildren = function( | | 298 | + parent: Instance, | | 299 | + workInProgress: Fiber, | | 300 | + needsVisibilityToggle: boolean, | | 301 | + isHidden: boolean, | | 302 | + ) { | 290 | 303 | // We only have the top Fiber that was created but we need recurse down its | 291 | 304 | // children to find all the terminal nodes. | 292 | 305 | let node = workInProgress.child; | 293 | 306 | while (node !== null) { | 294 | 307 | // eslint-disable-next-line no-labels | 295 | 308 | branches: if (node.tag === HostComponent) { | 296 | | - const instance = node.stateNode; | | 309 | + let instance = node.stateNode; | | 310 | + if (needsVisibilityToggle && isHidden) { | | 311 | + // This child is inside a timed out tree. Hide it. | | 312 | + const props = node.memoizedProps; | | 313 | + const type = node.type; | | 314 | + instance = cloneHiddenInstance(instance, type, props, node); | | 315 | + } | 297 | 316 | appendInitialChild(parent, instance); | 298 | 317 | } else if (node.tag === HostText) { | 299 | | - const instance = node.stateNode; | | 318 | + let instance = node.stateNode; | | 319 | + if (needsVisibilityToggle && isHidden) { | | 320 | + // This child is inside a timed out tree. Hide it. | | 321 | + const text = node.memoizedProps; | | 322 | + instance = cloneHiddenTextInstance(instance, text, node); | | 323 | + } | 300 | 324 | appendInitialChild(parent, instance); | 301 | 325 | } else if (node.tag === HostPortal) { | 302 | 326 | // If we have a portal child, then we don't want to traverse | 303 | 327 | // down its children. Instead, we'll get insertions from each child in | 304 | 328 | // the portal directly. | | 329 | + } else if ( | | 330 | + node.tag === OffscreenComponent && | | 331 | + node.memoizedState !== null | | 332 | + ) { | | 333 | + // The children in this boundary are hidden. Toggle their visibility | | 334 | + // before appending. | | 335 | + const child = node.child; | | 336 | + if (child !== null) { | | 337 | + child.return = node; | | 338 | + } | | 339 | + if (enablePersistentOffscreenHostContainer) { | | 340 | + appendAllChildren(parent, node, false, false); | | 341 | + } else { | | 342 | + appendAllChildren(parent, node, true, true); | | 343 | + } | 305 | 344 | } else if (node.child !== null) { | 306 | 345 | node.child.return = node; | 307 | 346 | node = node.child; | @@ -327,22 +366,50 @@ if (supportsMutation) { | 327 | 366 | const appendAllChildrenToContainer = function( | 328 | 367 | containerChildSet: ChildSet, | 329 | 368 | workInProgress: Fiber, | | 369 | + needsVisibilityToggle: boolean, | | 370 | + isHidden: boolean, | 330 | 371 | ) { | 331 | 372 | // We only have the top Fiber that was created but we need recurse down its | 332 | 373 | // children to find all the terminal nodes. | 333 | 374 | let node = workInProgress.child; | 334 | 375 | while (node !== null) { | 335 | 376 | // eslint-disable-next-line no-labels | 336 | 377 | branches: if (node.tag === HostComponent) { | 337 | | - const instance = node.stateNode; | | 378 | + let instance = node.stateNode; | | 379 | + if (needsVisibilityToggle && isHidden) { | | 380 | + // This child is inside a timed out tree. Hide it. | | 381 | + const props = node.memoizedProps; | | 382 | + const type = node.type; | | 383 | + instance = cloneHiddenInstance(instance, type, props, node); | | 384 | + } | 338 | 385 | appendChildToContainerChildSet(containerChildSet, instance); | 339 | 386 | } else if (node.tag === HostText) { | 340 | | - const instance = node.stateNode; | | 387 | + let instance = node.stateNode; | | 388 | + if (needsVisibilityToggle && isHidden) { | | 389 | + // This child is inside a timed out tree. Hide it. | | 390 | + const text = node.memoizedProps; | | 391 | + instance = cloneHiddenTextInstance(instance, text, node); | | 392 | + } | 341 | 393 | appendChildToContainerChildSet(containerChildSet, instance); | 342 | 394 | } else if (node.tag === HostPortal) { | 343 | 395 | // If we have a portal child, then we don't want to traverse | 344 | 396 | // down its children. Instead, we'll get insertions from each child in | 345 | 397 | // the portal directly. | | 398 | + } else if ( | | 399 | + node.tag === OffscreenComponent && | | 400 | + node.memoizedState !== null | | 401 | + ) { | | 402 | + // The children in this boundary are hidden. Toggle their visibility | | 403 | + // before appending. | | 404 | + const child = node.child; | | 405 | + if (child !== null) { | | 406 | + child.return = node; | | 407 | + } | | 408 | + if (enablePersistentOffscreenHostContainer) { | | 409 | + appendAllChildrenToContainer(containerChildSet, node, false, false); | | 410 | + } else { | | 411 | + appendAllChildrenToContainer(containerChildSet, node, true, true); | | 412 | + } | 346 | 413 | } else if (node.child !== null) { | 347 | 414 | node.child.return = node; | 348 | 415 | node = node.child; | @@ -376,7 +443,7 @@ if (supportsMutation) { | 376 | 443 | const container = portalOrRoot.containerInfo; | 377 | 444 | const newChildSet = createContainerChildSet(container); | 378 | 445 | // If children might have changed, we have to add them all to the set. | 379 | | - appendAllChildrenToContainer(newChildSet, workInProgress); | | 446 | + appendAllChildrenToContainer(newChildSet, workInProgress, false, false); | 380 | 447 | portalOrRoot.pendingChildren = newChildSet; | 381 | 448 | // Schedule an update on the container to swap out the container. | 382 | 449 | markUpdate(workInProgress); | @@ -449,7 +516,7 @@ if (supportsMutation) { | 449 | 516 | markUpdate(workInProgress); | 450 | 517 | } else { | 451 | 518 | // If children might have changed, we have to add them all to the set. | 452 | | - appendAllChildren(newInstance, workInProgress); | | 519 | + appendAllChildren(newInstance, workInProgress, false, false); | 453 | 520 | } | 454 | 521 | }; | 455 | 522 | updateHostText = function( | @@ -722,7 +789,7 @@ export function completeSuspendedOffscreenHostContainer( | 722 | 789 | workInProgress, | 723 | 790 | ); | 724 | 791 |
| 725 | | - appendAllChildren(instance, workInProgress); | | 792 | + appendAllChildren(instance, workInProgress, false, false); | 726 | 793 |
| 727 | 794 | workInProgress.stateNode = instance; | 728 | 795 |
| @@ -869,7 +936,7 @@ function completeWork( | 869 | 936 | workInProgress, | 870 | 937 | ); | 871 | 938 |
| 872 | | - appendAllChildren(instance, workInProgress); | | 939 | + appendAllChildren(instance, workInProgress, false, false); | 873 | 940 |
| 874 | 941 | workInProgress.stateNode = instance; | 875 | 942 |
| |
|