GeezerVison is showing github.com — Delete remaining references to effect list (#20625) · react/react@fceb75e
File treeExpand file treeCollapse file tree Open diff view settings packages/react-reconciler/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .eslintrc.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -116,7 +116,7 @@ module.exports = { | 116 | 116 | 'react-internal/no-cross-fork-types': [ | 117 | 117 | ERROR, | 118 | 118 | { | 119 | | - old: [], | | 119 | + old: ['firstEffect', 'nextEffect'], | 120 | 120 | new: [], | 121 | 121 | }, | 122 | 122 | ], | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactChildFiber.new.js -14Lines changed: 0 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -263,20 +263,6 @@ function ChildReconciler(shouldTrackSideEffects) { | 263 | 263 | // Noop. | 264 | 264 | return; | 265 | 265 | } | 266 | | - // Deletions are added in reversed order so we add it to the front. | 267 | | - // At this point, the return fiber's effect list is empty except for | 268 | | - // deletions, so we can just append the deletion to the list. The remaining | 269 | | - // effects aren't added until the complete phase. Once we implement | 270 | | - // resuming, this may not be true. | 271 | | - const last = returnFiber.lastEffect; | 272 | | - if (last !== null) { | 273 | | - last.nextEffect = childToDelete; | 274 | | - returnFiber.lastEffect = childToDelete; | 275 | | - } else { | 276 | | - returnFiber.firstEffect = returnFiber.lastEffect = childToDelete; | 277 | | - } | 278 | | - childToDelete.nextEffect = null; | 279 | | - | 280 | 266 | const deletions = returnFiber.deletions; | 281 | 267 | if (deletions === null) { | 282 | 268 | returnFiber.deletions = [childToDelete]; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiber.new.js +5-15Lines changed: 5 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -144,10 +144,6 @@ function FiberNode( | 144 | 144 |
| 145 | 145 | // Effects | 146 | 146 | this.flags = NoFlags; | 147 | | - this.nextEffect = null; | 148 | | - | 149 | | - this.firstEffect = null; | 150 | | - this.lastEffect = null; | 151 | 147 | this.subtreeFlags = NoFlags; | 152 | 148 | this.deletions = null; | 153 | 149 |
| @@ -285,10 +281,7 @@ export function createWorkInProgress(current: Fiber, pendingProps: any): Fiber { | 285 | 281 | // Reset the effect tag. | 286 | 282 | workInProgress.flags = NoFlags; | 287 | 283 |
| 288 | | - // The effect list is no longer valid. | 289 | | - workInProgress.nextEffect = null; | 290 | | - workInProgress.firstEffect = null; | 291 | | - workInProgress.lastEffect = null; | | 284 | + // The effects are no longer valid. | 292 | 285 | workInProgress.subtreeFlags = NoFlags; | 293 | 286 | workInProgress.deletions = null; | 294 | 287 |
| @@ -370,10 +363,7 @@ export function resetWorkInProgress(workInProgress: Fiber, renderLanes: Lanes) { | 370 | 363 | // that child fiber is setting, not the reconciliation. | 371 | 364 | workInProgress.flags &= StaticMask | Placement; | 372 | 365 |
| 373 | | - // The effect list is no longer valid. | 374 | | - workInProgress.nextEffect = null; | 375 | | - workInProgress.firstEffect = null; | 376 | | - workInProgress.lastEffect = null; | | 366 | + // The effects are no longer valid. | 377 | 367 |
| 378 | 368 | const current = workInProgress.alternate; | 379 | 369 | if (current === null) { | @@ -403,6 +393,9 @@ export function resetWorkInProgress(workInProgress: Fiber, renderLanes: Lanes) { | 403 | 393 | workInProgress.lanes = current.lanes; | 404 | 394 |
| 405 | 395 | workInProgress.child = current.child; | | 396 | + // TODO: `subtreeFlags` should be reset to NoFlags, like we do in | | 397 | + // `createWorkInProgress`. Nothing reads this until the complete phase, | | 398 | + // currently, but it might in the future, and we should be consistent. | 406 | 399 | workInProgress.subtreeFlags = current.subtreeFlags; | 407 | 400 | workInProgress.deletions = null; | 408 | 401 | workInProgress.memoizedProps = current.memoizedProps; | @@ -847,9 +840,6 @@ export function assignFiberPropertiesInDEV( | 847 | 840 | target.dependencies = source.dependencies; | 848 | 841 | target.mode = source.mode; | 849 | 842 | target.flags = source.flags; | 850 | | - target.nextEffect = source.nextEffect; | 851 | | - target.firstEffect = source.firstEffect; | 852 | | - target.lastEffect = source.lastEffect; | 853 | 843 | target.subtreeFlags = source.subtreeFlags; | 854 | 844 | target.deletions = source.deletions; | 855 | 845 | target.lanes = source.lanes; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.new.js +3-33Lines changed: 3 additions & 33 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2198,8 +2198,6 @@ function updateSuspensePrimaryChildren( | 2198 | 2198 | primaryChildFragment.sibling = null; | 2199 | 2199 | if (currentFallbackChildFragment !== null) { | 2200 | 2200 | // Delete the fallback child fragment | 2201 | | - currentFallbackChildFragment.nextEffect = null; | 2202 | | - workInProgress.firstEffect = workInProgress.lastEffect = currentFallbackChildFragment; | 2203 | 2201 | const deletions = workInProgress.deletions; | 2204 | 2202 | if (deletions === null) { | 2205 | 2203 | workInProgress.deletions = [currentFallbackChildFragment]; | @@ -2261,22 +2259,9 @@ function updateSuspenseFallbackChildren( | 2261 | 2259 | currentPrimaryChildFragment.treeBaseDuration; | 2262 | 2260 | } | 2263 | 2261 |
| 2264 | | - if (currentFallbackChildFragment !== null) { | 2265 | | - // The fallback fiber was added as a deletion effect during the first | 2266 | | - // pass. However, since we're going to remain on the fallback, we no | 2267 | | - // longer want to delete it. So we need to remove it from the list. | 2268 | | - // Deletions are stored on the same list as effects, and are always added | 2269 | | - // to the front. So we know that the first effect must be the fallback | 2270 | | - // deletion effect, and everything after that is from the primary free. | 2271 | | - const firstPrimaryTreeEffect = currentFallbackChildFragment.nextEffect; | 2272 | | - if (firstPrimaryTreeEffect !== null) { | 2273 | | - workInProgress.firstEffect = firstPrimaryTreeEffect; | 2274 | | - } else { | 2275 | | - // TODO: Reset this somewhere else? Lol legacy mode is so weird. | 2276 | | - workInProgress.firstEffect = workInProgress.lastEffect = null; | 2277 | | - } | 2278 | | - } | 2279 | | - | | 2262 | + // The fallback fiber was added as a deletion during the first pass. | | 2263 | + // However, since we're going to remain on the fallback, we no longer want | | 2264 | + // to delete it. | 2280 | 2265 | workInProgress.deletions = null; | 2281 | 2266 | } else { | 2282 | 2267 | primaryChildFragment = createWorkInProgressOffscreenFiber( | @@ -2773,7 +2758,6 @@ function initSuspenseListRenderState( | 2773 | 2758 | tail: null | Fiber, | 2774 | 2759 | lastContentRow: null | Fiber, | 2775 | 2760 | tailMode: SuspenseListTailMode, | 2776 | | - lastEffectBeforeRendering: null | Fiber, | 2777 | 2761 | ): void { | 2778 | 2762 | const renderState: null | SuspenseListRenderState = | 2779 | 2763 | workInProgress.memoizedState; | @@ -2785,7 +2769,6 @@ function initSuspenseListRenderState( | 2785 | 2769 | last: lastContentRow, | 2786 | 2770 | tail: tail, | 2787 | 2771 | tailMode: tailMode, | 2788 | | - lastEffect: lastEffectBeforeRendering, | 2789 | 2772 | }: SuspenseListRenderState); | 2790 | 2773 | } else { | 2791 | 2774 | // We can reuse the existing object from previous renders. | @@ -2795,7 +2778,6 @@ function initSuspenseListRenderState( | 2795 | 2778 | renderState.last = lastContentRow; | 2796 | 2779 | renderState.tail = tail; | 2797 | 2780 | renderState.tailMode = tailMode; | 2798 | | - renderState.lastEffect = lastEffectBeforeRendering; | 2799 | 2781 | } | 2800 | 2782 | } | 2801 | 2783 |
| @@ -2877,7 +2859,6 @@ function updateSuspenseListComponent( | 2877 | 2859 | tail, | 2878 | 2860 | lastContentRow, | 2879 | 2861 | tailMode, | 2880 | | - workInProgress.lastEffect, | 2881 | 2862 | ); | 2882 | 2863 | break; | 2883 | 2864 | } | @@ -2909,7 +2890,6 @@ function updateSuspenseListComponent( | 2909 | 2890 | tail, | 2910 | 2891 | null, // last | 2911 | 2892 | tailMode, | 2912 | | - workInProgress.lastEffect, | 2913 | 2893 | ); | 2914 | 2894 | break; | 2915 | 2895 | } | @@ -2920,7 +2900,6 @@ function updateSuspenseListComponent( | 2920 | 2900 | null, // tail | 2921 | 2901 | null, // last | 2922 | 2902 | undefined, | 2923 | | - workInProgress.lastEffect, | 2924 | 2903 | ); | 2925 | 2904 | break; | 2926 | 2905 | } | @@ -3180,15 +3159,6 @@ function remountFiber( | 3180 | 3159 |
| 3181 | 3160 | // Delete the old fiber and place the new one. | 3182 | 3161 | // Since the old fiber is disconnected, we have to schedule it manually. | 3183 | | - const last = returnFiber.lastEffect; | 3184 | | - if (last !== null) { | 3185 | | - last.nextEffect = current; | 3186 | | - returnFiber.lastEffect = current; | 3187 | | - } else { | 3188 | | - returnFiber.firstEffect = returnFiber.lastEffect = current; | 3189 | | - } | 3190 | | - current.nextEffect = null; | 3191 | | - | 3192 | 3162 | const deletions = returnFiber.deletions; | 3193 | 3163 | if (deletions === null) { | 3194 | 3164 | returnFiber.deletions = [current]; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCommitWork.new.js -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1213,9 +1213,6 @@ export function detachFiberAfterEffects(fiber: Fiber): void { | 1213 | 1213 | fiber.sibling = null; | 1214 | 1214 | fiber.stateNode = null; | 1215 | 1215 | fiber.updateQueue = null; | 1216 | | - fiber.nextEffect = null; | 1217 | | - fiber.firstEffect = null; | 1218 | | - fiber.lastEffect = null; | 1219 | 1216 |
| 1220 | 1217 | if (__DEV__) { | 1221 | 1218 | fiber._debugOwner = null; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCompleteWork.new.js +35-22Lines changed: 35 additions & 22 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -72,7 +72,9 @@ import { | 72 | 72 | NoFlags, | 73 | 73 | DidCapture, | 74 | 74 | Snapshot, | | 75 | + ChildDeletion, | 75 | 76 | StaticMask, | | 77 | + MutationMask, | 76 | 78 | } from './ReactFiberFlags'; | 77 | 79 | import invariant from 'shared/invariant'; | 78 | 80 |
| @@ -173,6 +175,31 @@ function markRef(workInProgress: Fiber) { | 173 | 175 | workInProgress.flags |= Ref; | 174 | 176 | } | 175 | 177 |
| | 178 | +function hadNoMutationsEffects(current: null | Fiber, completedWork: Fiber) { | | 179 | + const didBailout = current !== null && current.child === completedWork.child; | | 180 | + if (didBailout) { | | 181 | + return true; | | 182 | + } | | 183 | + | | 184 | + if ((completedWork.flags & ChildDeletion) !== NoFlags) { | | 185 | + return false; | | 186 | + } | | 187 | + | | 188 | + // TODO: If we move the `hadNoMutationsEffects` call after `bubbleProperties` | | 189 | + // then we only have to check the `completedWork.subtreeFlags`. | | 190 | + let child = completedWork.child; | | 191 | + while (child !== null) { | | 192 | + if ( | | 193 | + (child.flags & MutationMask) !== NoFlags || | | 194 | + (child.subtreeFlags & MutationMask) !== NoFlags | | 195 | + ) { | | 196 | + return false; | | 197 | + } | | 198 | + child = child.sibling; | | 199 | + } | | 200 | + return true; | | 201 | +} | | 202 | + | 176 | 203 | let appendAllChildren; | 177 | 204 | let updateHostContainer; | 178 | 205 | let updateHostComponent; | @@ -217,7 +244,7 @@ if (supportsMutation) { | 217 | 244 | } | 218 | 245 | }; | 219 | 246 |
| 220 | | - updateHostContainer = function(workInProgress: Fiber) { | | 247 | + updateHostContainer = function(current: null | Fiber, workInProgress: Fiber) { | 221 | 248 | // Noop | 222 | 249 | }; | 223 | 250 | updateHostComponent = function( | @@ -461,13 +488,13 @@ if (supportsMutation) { | 461 | 488 | node = node.sibling; | 462 | 489 | } | 463 | 490 | }; | 464 | | - updateHostContainer = function(workInProgress: Fiber) { | | 491 | + updateHostContainer = function(current: null | Fiber, workInProgress: Fiber) { | 465 | 492 | const portalOrRoot: { | 466 | 493 | containerInfo: Container, | 467 | 494 | pendingChildren: ChildSet, | 468 | 495 | ... | 469 | 496 | } = workInProgress.stateNode; | 470 | | - const childrenUnchanged = workInProgress.firstEffect === null; | | 497 | + const childrenUnchanged = hadNoMutationsEffects(current, workInProgress); | 471 | 498 | if (childrenUnchanged) { | 472 | 499 | // No changes, just reuse the existing instance. | 473 | 500 | } else { | @@ -492,7 +519,7 @@ if (supportsMutation) { | 492 | 519 | const oldProps = current.memoizedProps; | 493 | 520 | // If there are no effects associated with this node, then none of our children had any updates. | 494 | 521 | // This guarantees that we can reuse all of them. | 495 | | - const childrenUnchanged = workInProgress.firstEffect === null; | | 522 | + const childrenUnchanged = hadNoMutationsEffects(current, workInProgress); | 496 | 523 | if (childrenUnchanged && oldProps === newProps) { | 497 | 524 | // No changes, just reuse the existing instance. | 498 | 525 | // Note that this might release a previous clone. | @@ -575,7 +602,7 @@ if (supportsMutation) { | 575 | 602 | }; | 576 | 603 | } else { | 577 | 604 | // No host operations | 578 | | - updateHostContainer = function(workInProgress: Fiber) { | | 605 | + updateHostContainer = function(current: null | Fiber, workInProgress: Fiber) { | 579 | 606 | // Noop | 580 | 607 | }; | 581 | 608 | updateHostComponent = function( | @@ -847,7 +874,7 @@ function completeWork( | 847 | 874 | workInProgress.flags |= Snapshot; | 848 | 875 | } | 849 | 876 | } | 850 | | - updateHostContainer(workInProgress); | | 877 | + updateHostContainer(current, workInProgress); | 851 | 878 | bubbleProperties(workInProgress); | 852 | 879 | return null; | 853 | 880 | } | @@ -1142,7 +1169,7 @@ function completeWork( | 1142 | 1169 | } | 1143 | 1170 | case HostPortal: | 1144 | 1171 | popHostContainer(workInProgress); | 1145 | | - updateHostContainer(workInProgress); | | 1172 | + updateHostContainer(current, workInProgress); | 1146 | 1173 | if (current === null) { | 1147 | 1174 | preparePortalMount(workInProgress.stateNode.containerInfo); | 1148 | 1175 | } | @@ -1226,11 +1253,7 @@ function completeWork( | 1226 | 1253 |
| 1227 | 1254 | // Rerender the whole list, but this time, we'll force fallbacks | 1228 | 1255 | // to stay in place. | 1229 | | - // Reset the effect list before doing the second pass since that's now invalid. | 1230 | | - if (renderState.lastEffect === null) { | 1231 | | - workInProgress.firstEffect = null; | 1232 | | - } | 1233 | | - workInProgress.lastEffect = renderState.lastEffect; | | 1256 | + // Reset the effect flags before doing the second pass since that's now invalid. | 1234 | 1257 | // Reset the child fibers to their original state. | 1235 | 1258 | workInProgress.subtreeFlags = NoFlags; | 1236 | 1259 | resetChildFibers(workInProgress, renderLanes); | @@ -1301,15 +1324,6 @@ function completeWork( | 1301 | 1324 | !renderedTail.alternate && | 1302 | 1325 | !getIsHydrating() // We don't cut it if we're hydrating. | 1303 | 1326 | ) { | 1304 | | - // We need to delete the row we just rendered. | 1305 | | - // Reset the effect list to what it was before we rendered this | 1306 | | - // child. The nested children have already appended themselves. | 1307 | | - const lastEffect = (workInProgress.lastEffect = | 1308 | | - renderState.lastEffect); | 1309 | | - // Remove any effects that were appended after this point. | 1310 | | - if (lastEffect !== null) { | 1311 | | - lastEffect.nextEffect = null; | 1312 | | - } | 1313 | 1327 | // We're done. | 1314 | 1328 | bubbleProperties(workInProgress); | 1315 | 1329 | return null; | @@ -1369,7 +1383,6 @@ function completeWork( | 1369 | 1383 | const next = renderState.tail; | 1370 | 1384 | renderState.rendering = next; | 1371 | 1385 | renderState.tail = next.sibling; | 1372 | | - renderState.lastEffect = workInProgress.lastEffect; | 1373 | 1386 | renderState.renderingStartTime = now(); | 1374 | 1387 | next.sibling = null; | 1375 | 1388 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHydrationContext.new.js -12Lines changed: 0 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -125,18 +125,6 @@ function deleteHydratableInstance( | 125 | 125 | childToDelete.stateNode = instance; | 126 | 126 | childToDelete.return = returnFiber; | 127 | 127 |
| 128 | | - // This might seem like it belongs on progressedFirstDeletion. However, | 129 | | - // these children are not part of the reconciliation list of children. | 130 | | - // Even if we abort and rereconcile the children, that will try to hydrate | 131 | | - // again and the nodes are still in the host tree so these will be | 132 | | - // recreated. | 133 | | - if (returnFiber.lastEffect !== null) { | 134 | | - returnFiber.lastEffect.nextEffect = childToDelete; | 135 | | - returnFiber.lastEffect = childToDelete; | 136 | | - } else { | 137 | | - returnFiber.firstEffect = returnFiber.lastEffect = childToDelete; | 138 | | - } | 139 | | - | 140 | 128 | const deletions = returnFiber.deletions; | 141 | 129 | if (deletions === null) { | 142 | 130 | returnFiber.deletions = [childToDelete]; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberSuspenseComponent.new.js -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -60,9 +60,6 @@ export type SuspenseListRenderState = {| | 60 | 60 | tail: null | Fiber, | 61 | 61 | // Tail insertions setting. | 62 | 62 | tailMode: SuspenseListTailMode, | 63 | | - // Last Effect before we rendered the "rendering" item. | 64 | | - // Used to remove new effects added by the rendered item. | 65 | | - lastEffect: null | Fiber, | 66 | 63 | |}; | 67 | 64 |
| 68 | 65 | export function shouldCaptureSuspense( | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberThrow.new.js -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -188,8 +188,6 @@ function throwException( | 188 | 188 | ) { | 189 | 189 | // The source fiber did not complete. | 190 | 190 | sourceFiber.flags |= Incomplete; | 191 | | - // Its effect list is no longer valid. | 192 | | - sourceFiber.firstEffect = sourceFiber.lastEffect = null; | 193 | 191 |
| 194 | 192 | if ( | 195 | 193 | value !== null && | |
|