GeezerVison is showing github.com — Suspense for CPU-bound trees (#19936) · react/react@1faf9e3
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: packages/react-reconciler/src/ReactFiberBeginWork.new.js +33-3Lines changed: 33 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -109,6 +109,7 @@ import { | 109 | 109 | SyncLane, | 110 | 110 | OffscreenLane, | 111 | 111 | DefaultHydrationLane, | | 112 | + SomeRetryLane, | 112 | 113 | NoTimestamp, | 113 | 114 | includesSomeLane, | 114 | 115 | laneToLanes, | @@ -1658,6 +1659,7 @@ function updateSuspenseOffscreenState( | 1658 | 1659 | }; | 1659 | 1660 | } | 1660 | 1661 |
| | 1662 | +// TODO: Probably should inline this back | 1661 | 1663 | function shouldRemainOnFallback( | 1662 | 1664 | suspenseContext: SuspenseContext, | 1663 | 1665 | current: null | Fiber, | @@ -1790,9 +1792,9 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) { | 1790 | 1792 | } | 1791 | 1793 | } | 1792 | 1794 |
| | 1795 | + const nextPrimaryChildren = nextProps.children; | | 1796 | + const nextFallbackChildren = nextProps.fallback; | 1793 | 1797 | if (showFallback) { | 1794 | | - const nextPrimaryChildren = nextProps.children; | 1795 | | - const nextFallbackChildren = nextProps.fallback; | 1796 | 1798 | const fallbackFragment = mountSuspenseFallbackChildren( | 1797 | 1799 | workInProgress, | 1798 | 1800 | nextPrimaryChildren, | @@ -1805,8 +1807,36 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) { | 1805 | 1807 | ); | 1806 | 1808 | workInProgress.memoizedState = SUSPENDED_MARKER; | 1807 | 1809 | return fallbackFragment; | | 1810 | + } else if (typeof nextProps.unstable_expectedLoadTime === 'number') { | | 1811 | + // This is a CPU-bound tree. Skip this tree and show a placeholder to | | 1812 | + // unblock the surrounding content. Then immediately retry after the | | 1813 | + // initial commit. | | 1814 | + const fallbackFragment = mountSuspenseFallbackChildren( | | 1815 | + workInProgress, | | 1816 | + nextPrimaryChildren, | | 1817 | + nextFallbackChildren, | | 1818 | + renderLanes, | | 1819 | + ); | | 1820 | + const primaryChildFragment: Fiber = (workInProgress.child: any); | | 1821 | + primaryChildFragment.memoizedState = mountSuspenseOffscreenState( | | 1822 | + renderLanes, | | 1823 | + ); | | 1824 | + workInProgress.memoizedState = SUSPENDED_MARKER; | | 1825 | + | | 1826 | + // Since nothing actually suspended, there will nothing to ping this to | | 1827 | + // get it started back up to attempt the next item. While in terms of | | 1828 | + // priority this work has the same priority as this current render, it's | | 1829 | + // not part of the same transition once the transition has committed. If | | 1830 | + // it's sync, we still want to yield so that it can be painted. | | 1831 | + // Conceptually, this is really the same as pinging. We can use any | | 1832 | + // RetryLane even if it's the one currently rendering since we're leaving | | 1833 | + // it behind on this node. | | 1834 | + workInProgress.lanes = SomeRetryLane; | | 1835 | + if (enableSchedulerTracing) { | | 1836 | + markSpawnedWork(SomeRetryLane); | | 1837 | + } | | 1838 | + return fallbackFragment; | 1808 | 1839 | } else { | 1809 | | - const nextPrimaryChildren = nextProps.children; | 1810 | 1840 | return mountSuspensePrimaryChildren( | 1811 | 1841 | workInProgress, | 1812 | 1842 | nextPrimaryChildren, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.old.js +33-3Lines changed: 33 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -109,6 +109,7 @@ import { | 109 | 109 | SyncLane, | 110 | 110 | OffscreenLane, | 111 | 111 | DefaultHydrationLane, | | 112 | + SomeRetryLane, | 112 | 113 | NoTimestamp, | 113 | 114 | includesSomeLane, | 114 | 115 | laneToLanes, | @@ -1657,6 +1658,7 @@ function updateSuspenseOffscreenState( | 1657 | 1658 | }; | 1658 | 1659 | } | 1659 | 1660 |
| | 1661 | +// TODO: Probably should inline this back | 1660 | 1662 | function shouldRemainOnFallback( | 1661 | 1663 | suspenseContext: SuspenseContext, | 1662 | 1664 | current: null | Fiber, | @@ -1789,9 +1791,9 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) { | 1789 | 1791 | } | 1790 | 1792 | } | 1791 | 1793 |
| | 1794 | + const nextPrimaryChildren = nextProps.children; | | 1795 | + const nextFallbackChildren = nextProps.fallback; | 1792 | 1796 | if (showFallback) { | 1793 | | - const nextPrimaryChildren = nextProps.children; | 1794 | | - const nextFallbackChildren = nextProps.fallback; | 1795 | 1797 | const fallbackFragment = mountSuspenseFallbackChildren( | 1796 | 1798 | workInProgress, | 1797 | 1799 | nextPrimaryChildren, | @@ -1804,8 +1806,36 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) { | 1804 | 1806 | ); | 1805 | 1807 | workInProgress.memoizedState = SUSPENDED_MARKER; | 1806 | 1808 | return fallbackFragment; | | 1809 | + } else if (typeof nextProps.unstable_expectedLoadTime === 'number') { | | 1810 | + // This is a CPU-bound tree. Skip this tree and show a placeholder to | | 1811 | + // unblock the surrounding content. Then immediately retry after the | | 1812 | + // initial commit. | | 1813 | + const fallbackFragment = mountSuspenseFallbackChildren( | | 1814 | + workInProgress, | | 1815 | + nextPrimaryChildren, | | 1816 | + nextFallbackChildren, | | 1817 | + renderLanes, | | 1818 | + ); | | 1819 | + const primaryChildFragment: Fiber = (workInProgress.child: any); | | 1820 | + primaryChildFragment.memoizedState = mountSuspenseOffscreenState( | | 1821 | + renderLanes, | | 1822 | + ); | | 1823 | + workInProgress.memoizedState = SUSPENDED_MARKER; | | 1824 | + | | 1825 | + // Since nothing actually suspended, there will nothing to ping this to | | 1826 | + // get it started back up to attempt the next item. While in terms of | | 1827 | + // priority this work has the same priority as this current render, it's | | 1828 | + // not part of the same transition once the transition has committed. If | | 1829 | + // it's sync, we still want to yield so that it can be painted. | | 1830 | + // Conceptually, this is really the same as pinging. We can use any | | 1831 | + // RetryLane even if it's the one currently rendering since we're leaving | | 1832 | + // it behind on this node. | | 1833 | + workInProgress.lanes = SomeRetryLane; | | 1834 | + if (enableSchedulerTracing) { | | 1835 | + markSpawnedWork(SomeRetryLane); | | 1836 | + } | | 1837 | + return fallbackFragment; | 1807 | 1838 | } else { | 1808 | | - const nextPrimaryChildren = nextProps.children; | 1809 | 1839 | return mountSuspensePrimaryChildren( | 1810 | 1840 | workInProgress, | 1811 | 1841 | nextPrimaryChildren, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberSuspenseComponent.new.js +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | * @flow | 8 | 8 | */ | 9 | 9 |
| | 10 | +import type {ReactNodeList, Wakeable} from 'shared/ReactTypes'; | 10 | 11 | import type {Fiber} from './ReactInternalTypes'; | 11 | 12 | import type {SuspenseInstance} from './ReactFiberHostConfig'; | 12 | 13 | import type {Lane} from './ReactFiberLane'; | @@ -17,6 +18,16 @@ import { | 17 | 18 | isSuspenseInstanceFallback, | 18 | 19 | } from './ReactFiberHostConfig'; | 19 | 20 |
| | 21 | +export type SuspenseProps = {| | | 22 | + children?: ReactNodeList, | | 23 | + fallback?: ReactNodeList, | | 24 | + | | 25 | + // TODO: Add "unstable_" prefix? | | 26 | + suspenseCallback?: (Set<Wakeable> | null) => mixed, | | 27 | + | | 28 | + unstable_expectedLoadTime?: number, | | 29 | +|}; | | 30 | + | 20 | 31 | // A null SuspenseState represents an unsuspended normal Suspense boundary. | 21 | 32 | // A non-null SuspenseState means that it is blocked for one reason or another. | 22 | 33 | // - A non-null dehydrated field means it's blocked pending hydration. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberSuspenseComponent.old.js +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | * @flow | 8 | 8 | */ | 9 | 9 |
| | 10 | +import type {ReactNodeList, Wakeable} from 'shared/ReactTypes'; | 10 | 11 | import type {Fiber} from './ReactInternalTypes'; | 11 | 12 | import type {SuspenseInstance} from './ReactFiberHostConfig'; | 12 | 13 | import type {Lane} from './ReactFiberLane'; | @@ -17,6 +18,16 @@ import { | 17 | 18 | isSuspenseInstanceFallback, | 18 | 19 | } from './ReactFiberHostConfig'; | 19 | 20 |
| | 21 | +export type SuspenseProps = {| | | 22 | + children?: ReactNodeList, | | 23 | + fallback?: ReactNodeList, | | 24 | + | | 25 | + // TODO: Add "unstable_" prefix? | | 26 | + suspenseCallback?: (Set<Wakeable> | null) => mixed, | | 27 | + | | 28 | + unstable_expectedLoadTime?: number, | | 29 | +|}; | | 30 | + | 20 | 31 | // A null SuspenseState represents an unsuspended normal Suspense boundary. | 21 | 32 | // A non-null SuspenseState means that it is blocked for one reason or another. | 22 | 33 | // - A non-null dehydrated field means it's blocked pending hydration. | |
|