@@ -139,15 +139,8 @@ import { |
139 | 139 | MutationMask, |
140 | 140 | LayoutMask, |
141 | 141 | PassiveMask, |
| 142 | + StaticMask, |
142 | 143 | } from './ReactFiberFlags'; |
143 | | -import { |
144 | | - NoFlags as NoSubtreeFlags, |
145 | | - BeforeMutation as BeforeMutationSubtreeFlags, |
146 | | - Mutation as MutationSubtreeFlags, |
147 | | - Layout as LayoutSubtreeFlags, |
148 | | - Passive as PassiveSubtreeFlags, |
149 | | - PassiveStatic as PassiveStaticSubtreeFlags, |
150 | | -} from './ReactSubtreeFlags'; |
151 | 144 | import { |
152 | 145 | NoLanePriority, |
153 | 146 | SyncLanePriority, |
@@ -1766,7 +1759,7 @@ function completeUnitOfWork(unitOfWork: Fiber): void { |
1766 | 1759 | if (returnFiber !== null) { |
1767 | 1760 | // Mark the parent fiber as incomplete |
1768 | 1761 | returnFiber.flags |= Incomplete; |
1769 | | - returnFiber.subtreeFlags = NoSubtreeFlags; |
| 1762 | + returnFiber.subtreeFlags = NoFlags; |
1770 | 1763 | returnFiber.deletions = null; |
1771 | 1764 | } |
1772 | 1765 | } |
@@ -1809,7 +1802,7 @@ function resetChildLanes(completedWork: Fiber) { |
1809 | 1802 | completedWork.alternate.child === completedWork.child; |
1810 | 1803 |
|
1811 | 1804 | let newChildLanes = NoLanes; |
1812 | | - let subtreeFlags = NoSubtreeFlags; |
| 1805 | + let subtreeFlags = NoFlags; |
1813 | 1806 |
|
1814 | 1807 | if (!didBailout) { |
1815 | 1808 | // Bubble up the earliest expiration time. |
@@ -1827,23 +1820,7 @@ function resetChildLanes(completedWork: Fiber) { |
1827 | 1820 | ); |
1828 | 1821 |
|
1829 | 1822 | subtreeFlags |= child.subtreeFlags; |
1830 | | - |
1831 | | - const flags = child.flags; |
1832 | | - if ((flags & BeforeMutationMask) !== NoFlags) { |
1833 | | - subtreeFlags |= BeforeMutationSubtreeFlags; |
1834 | | - } |
1835 | | - if ((flags & MutationMask) !== NoFlags) { |
1836 | | - subtreeFlags |= MutationSubtreeFlags; |
1837 | | - } |
1838 | | - if ((flags & LayoutMask) !== NoFlags) { |
1839 | | - subtreeFlags |= LayoutSubtreeFlags; |
1840 | | - } |
1841 | | - if ((flags & PassiveMask) !== NoFlags) { |
1842 | | - subtreeFlags |= PassiveSubtreeFlags; |
1843 | | - } |
1844 | | - if ((flags & PassiveStatic) !== NoFlags) { |
1845 | | - subtreeFlags |= PassiveStaticSubtreeFlags; |
1846 | | - } |
| 1823 | + subtreeFlags |= child.flags; |
1847 | 1824 |
|
1848 | 1825 | // When a fiber is cloned, its actualDuration is reset to 0. This value will |
1849 | 1826 | // only be updated if work is done on the fiber (i.e. it doesn't bailout). |
@@ -1880,23 +1857,7 @@ function resetChildLanes(completedWork: Fiber) { |
1880 | 1857 | ); |
1881 | 1858 |
|
1882 | 1859 | subtreeFlags |= child.subtreeFlags; |
1883 | | - |
1884 | | - const flags = child.flags; |
1885 | | - if ((flags & BeforeMutationMask) !== NoFlags) { |
1886 | | - subtreeFlags |= BeforeMutationSubtreeFlags; |
1887 | | - } |
1888 | | - if ((flags & MutationMask) !== NoFlags) { |
1889 | | - subtreeFlags |= MutationSubtreeFlags; |
1890 | | - } |
1891 | | - if ((flags & LayoutMask) !== NoFlags) { |
1892 | | - subtreeFlags |= LayoutSubtreeFlags; |
1893 | | - } |
1894 | | - if ((flags & PassiveMask) !== NoFlags) { |
1895 | | - subtreeFlags |= PassiveSubtreeFlags; |
1896 | | - } |
1897 | | - if ((flags & PassiveStatic) !== NoFlags) { |
1898 | | - subtreeFlags |= PassiveStaticSubtreeFlags; |
1899 | | - } |
| 1860 | + subtreeFlags |= child.flags; |
1900 | 1861 |
|
1901 | 1862 | child = child.sibling; |
1902 | 1863 | } |
@@ -1917,13 +1878,12 @@ function resetChildLanes(completedWork: Fiber) { |
1917 | 1878 | mergeLanes(child.lanes, child.childLanes), |
1918 | 1879 | ); |
1919 | 1880 |
|
1920 | | - // Preserve passive static flag even in the case of a bailout; |
1921 | | - // otherwise a subsequent unmount may bailout before calling destroy functions. |
1922 | | - subtreeFlags |= child.subtreeFlags & PassiveStaticSubtreeFlags; |
1923 | | - const flags = child.flags; |
1924 | | - if ((flags & PassiveStatic) !== NoFlags) { |
1925 | | - subtreeFlags |= PassiveStaticSubtreeFlags; |
1926 | | - } |
| 1881 | + // "Static" flags share the lifetime of the fiber/hook they belong to, |
| 1882 | + // so we should bubble those up even during a bailout. All the other |
| 1883 | + // flags have a lifetime only of a single render + commit, so we should |
| 1884 | + // ignore them. |
| 1885 | + subtreeFlags |= child.subtreeFlags & StaticMask; |
| 1886 | + subtreeFlags |= child.flags & StaticMask; |
1927 | 1887 |
|
1928 | 1888 | treeBaseDuration += child.treeBaseDuration; |
1929 | 1889 | child = child.sibling; |
@@ -1949,13 +1909,12 @@ function resetChildLanes(completedWork: Fiber) { |
1949 | 1909 | mergeLanes(child.lanes, child.childLanes), |
1950 | 1910 | ); |
1951 | 1911 |
|
1952 | | - // Preserve passive static flag even in the case of a bailout; |
1953 | | - // otherwise a subsequent unmount may bailout before calling destroy functions. |
1954 | | - subtreeFlags |= child.subtreeFlags & PassiveStaticSubtreeFlags; |
1955 | | - const flags = child.flags; |
1956 | | - if ((flags & PassiveStatic) !== NoFlags) { |
1957 | | - subtreeFlags |= PassiveStaticSubtreeFlags; |
1958 | | - } |
| 1912 | + // "Static" flags share the lifetime of the fiber/hook they belong to, |
| 1913 | + // so we should bubble those up even during a bailout. All the other |
| 1914 | + // flags have a lifetime only of a single render + commit, so we should |
| 1915 | + // ignore them. |
| 1916 | + subtreeFlags |= child.subtreeFlags & StaticMask; |
| 1917 | + subtreeFlags |= child.flags & StaticMask; |
1959 | 1918 |
|
1960 | 1919 | child = child.sibling; |
1961 | 1920 | } |
@@ -2067,11 +2026,8 @@ function commitRootImpl(root, renderPriorityLevel) { |
2067 | 2026 | // Reconsider whether this is necessary. |
2068 | 2027 | const subtreeHasEffects = |
2069 | 2028 | (finishedWork.subtreeFlags & |
2070 | | - (BeforeMutationSubtreeFlags | |
2071 | | - MutationSubtreeFlags | |
2072 | | - LayoutSubtreeFlags | |
2073 | | - PassiveSubtreeFlags)) !== |
2074 | | - NoSubtreeFlags; |
| 2029 | + (BeforeMutationMask | MutationMask | LayoutMask | PassiveMask)) !== |
| 2030 | + NoFlags; |
2075 | 2031 | const rootHasEffect = |
2076 | 2032 | (finishedWork.flags & |
2077 | 2033 | (BeforeMutationMask | MutationMask | LayoutMask | PassiveMask)) !== |
@@ -2152,7 +2108,7 @@ function commitRootImpl(root, renderPriorityLevel) { |
2152 | 2108 |
|
2153 | 2109 | // If there are pending passive effects, schedule a callback to process them. |
2154 | 2110 | if ( |
2155 | | - (finishedWork.subtreeFlags & PassiveSubtreeFlags) !== NoSubtreeFlags || |
| 2111 | + (finishedWork.subtreeFlags & PassiveMask) !== NoFlags || |
2156 | 2112 | (finishedWork.flags & PassiveMask) !== NoFlags |
2157 | 2113 | ) { |
2158 | 2114 | if (!rootDoesHavePassiveEffects) { |
@@ -2306,9 +2262,8 @@ function commitBeforeMutationEffects(firstChild: Fiber) { |
2306 | 2262 | } |
2307 | 2263 |
|
2308 | 2264 | if (fiber.child !== null) { |
2309 | | - const primarySubtreeFlags = |
2310 | | - fiber.subtreeFlags & BeforeMutationSubtreeFlags; |
2311 | | - if (primarySubtreeFlags !== NoSubtreeFlags) { |
| 2265 | + const primarySubtreeFlags = fiber.subtreeFlags & BeforeMutationMask; |
| 2266 | + if (primarySubtreeFlags !== NoFlags) { |
2312 | 2267 | commitBeforeMutationEffects(fiber.child); |
2313 | 2268 | } |
2314 | 2269 | } |
@@ -2402,8 +2357,8 @@ function commitMutationEffects( |
2402 | 2357 | } |
2403 | 2358 |
|
2404 | 2359 | if (fiber.child !== null) { |
2405 | | - const primarySubtreeFlags = fiber.subtreeFlags & MutationSubtreeFlags; |
2406 | | - if (primarySubtreeFlags !== NoSubtreeFlags) { |
| 2360 | + const mutationFlags = fiber.subtreeFlags & MutationMask; |
| 2361 | + if (mutationFlags !== NoFlags) { |
2407 | 2362 | commitMutationEffects(fiber.child, root, renderPriorityLevel); |
2408 | 2363 | } |
2409 | 2364 | } |
@@ -2560,8 +2515,8 @@ function commitLayoutEffects( |
2560 | 2515 | let fiber = firstChild; |
2561 | 2516 | while (fiber !== null) { |
2562 | 2517 | if (fiber.child !== null) { |
2563 | | - const primarySubtreeFlags = fiber.subtreeFlags & LayoutSubtreeFlags; |
2564 | | - if (primarySubtreeFlags !== NoSubtreeFlags) { |
| 2518 | + const primarySubtreeFlags = fiber.subtreeFlags & LayoutMask; |
| 2519 | + if (primarySubtreeFlags !== NoFlags) { |
2565 | 2520 | commitLayoutEffects(fiber.child, root, committedLanes); |
2566 | 2521 | } |
2567 | 2522 | } |
@@ -2662,9 +2617,9 @@ export function enqueuePendingPassiveProfilerEffect(fiber: Fiber): void { |
2662 | 2617 | function flushPassiveMountEffects(firstChild: Fiber): void { |
2663 | 2618 | let fiber = firstChild; |
2664 | 2619 | while (fiber !== null) { |
2665 | | - const primarySubtreeFlags = fiber.subtreeFlags & PassiveSubtreeFlags; |
| 2620 | + const primarySubtreeFlags = fiber.subtreeFlags & PassiveMask; |
2666 | 2621 |
|
2667 | | - if (fiber.child !== null && primarySubtreeFlags !== NoSubtreeFlags) { |
| 2622 | + if (fiber.child !== null && primarySubtreeFlags !== NoFlags) { |
2668 | 2623 | flushPassiveMountEffects(fiber.child); |
2669 | 2624 | } |
2670 | 2625 |
|
@@ -2698,8 +2653,8 @@ function flushPassiveUnmountEffects(firstChild: Fiber): void { |
2698 | 2653 | // Note that this requires checking subtreeFlags of the current Fiber, |
2699 | 2654 | // rather than the subtreeFlags/effectsTag of the first child, |
2700 | 2655 | // since that would not cover passive effects in siblings. |
2701 | | - const primarySubtreeFlags = fiber.subtreeFlags & PassiveSubtreeFlags; |
2702 | | - if (primarySubtreeFlags !== NoSubtreeFlags) { |
| 2656 | + const passiveFlags = fiber.subtreeFlags & PassiveMask; |
| 2657 | + if (passiveFlags !== NoFlags) { |
2703 | 2658 | flushPassiveUnmountEffects(child); |
2704 | 2659 | } |
2705 | 2660 | } |
@@ -2719,10 +2674,7 @@ function flushPassiveUnmountEffectsInsideOfDeletedTree( |
2719 | 2674 | fiberToDelete: Fiber, |
2720 | 2675 | nearestMountedAncestor: Fiber, |
2721 | 2676 | ): void { |
2722 | | - if ( |
2723 | | - (fiberToDelete.subtreeFlags & PassiveStaticSubtreeFlags) !== |
2724 | | - NoSubtreeFlags |
2725 | | - ) { |
| 2677 | + if ((fiberToDelete.subtreeFlags & PassiveStatic) !== NoFlags) { |
2726 | 2678 | // If any children have passive effects then traverse the subtree. |
2727 | 2679 | // Note that this requires checking subtreeFlags of the current Fiber, |
2728 | 2680 | // rather than the subtreeFlags/effectsTag of the first child, |
|