GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Suspense for CPU-bound trees (#19936) · react/react@1faf9e3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/react-reconciler/src
    • ReactFiberBeginWork.new.js
    • ReactFiberBeginWork.old.js
    • ReactFiberSuspenseComponent.new.js
    • ReactFiberSuspenseComponent.old.js
    • __tests__
      • ReactCPUSuspense-test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/react-reconciler/src/ReactFiberBeginWork.new.js‎

Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.new.js
+33-3Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ import {
109109
SyncLane,
110110
OffscreenLane,
111111
DefaultHydrationLane,
112+
SomeRetryLane,
112113
NoTimestamp,
113114
includesSomeLane,
114115
laneToLanes,
@@ -1658,6 +1659,7 @@ function updateSuspenseOffscreenState(
16581659
};
16591660
}
16601661

1662+
// TODO: Probably should inline this back
16611663
function shouldRemainOnFallback(
16621664
suspenseContext: SuspenseContext,
16631665
current: null | Fiber,
@@ -1790,9 +1792,9 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
17901792
}
17911793
}
17921794

1795+
const nextPrimaryChildren = nextProps.children;
1796+
const nextFallbackChildren = nextProps.fallback;
17931797
if (showFallback) {
1794-
const nextPrimaryChildren = nextProps.children;
1795-
const nextFallbackChildren = nextProps.fallback;
17961798
const fallbackFragment = mountSuspenseFallbackChildren(
17971799
workInProgress,
17981800
nextPrimaryChildren,
@@ -1805,8 +1807,36 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
18051807
);
18061808
workInProgress.memoizedState = SUSPENDED_MARKER;
18071809
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;
18081839
} else {
1809-
const nextPrimaryChildren = nextProps.children;
18101840
return mountSuspensePrimaryChildren(
18111841
workInProgress,
18121842
nextPrimaryChildren,
Collapse file

‎packages/react-reconciler/src/ReactFiberBeginWork.old.js‎

Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.old.js
+33-3Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ import {
109109
SyncLane,
110110
OffscreenLane,
111111
DefaultHydrationLane,
112+
SomeRetryLane,
112113
NoTimestamp,
113114
includesSomeLane,
114115
laneToLanes,
@@ -1657,6 +1658,7 @@ function updateSuspenseOffscreenState(
16571658
};
16581659
}
16591660

1661+
// TODO: Probably should inline this back
16601662
function shouldRemainOnFallback(
16611663
suspenseContext: SuspenseContext,
16621664
current: null | Fiber,
@@ -1789,9 +1791,9 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
17891791
}
17901792
}
17911793

1794+
const nextPrimaryChildren = nextProps.children;
1795+
const nextFallbackChildren = nextProps.fallback;
17921796
if (showFallback) {
1793-
const nextPrimaryChildren = nextProps.children;
1794-
const nextFallbackChildren = nextProps.fallback;
17951797
const fallbackFragment = mountSuspenseFallbackChildren(
17961798
workInProgress,
17971799
nextPrimaryChildren,
@@ -1804,8 +1806,36 @@ function updateSuspenseComponent(current, workInProgress, renderLanes) {
18041806
);
18051807
workInProgress.memoizedState = SUSPENDED_MARKER;
18061808
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;
18071838
} else {
1808-
const nextPrimaryChildren = nextProps.children;
18091839
return mountSuspensePrimaryChildren(
18101840
workInProgress,
18111841
nextPrimaryChildren,
Collapse file

‎packages/react-reconciler/src/ReactFiberSuspenseComponent.new.js‎

Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberSuspenseComponent.new.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @flow
88
*/
99

10+
import type {ReactNodeList, Wakeable} from 'shared/ReactTypes';
1011
import type {Fiber} from './ReactInternalTypes';
1112
import type {SuspenseInstance} from './ReactFiberHostConfig';
1213
import type {Lane} from './ReactFiberLane';
@@ -17,6 +18,16 @@ import {
1718
isSuspenseInstanceFallback,
1819
} from './ReactFiberHostConfig';
1920

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+
2031
// A null SuspenseState represents an unsuspended normal Suspense boundary.
2132
// A non-null SuspenseState means that it is blocked for one reason or another.
2233
// - A non-null dehydrated field means it's blocked pending hydration.
Collapse file

‎packages/react-reconciler/src/ReactFiberSuspenseComponent.old.js‎

Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberSuspenseComponent.old.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @flow
88
*/
99

10+
import type {ReactNodeList, Wakeable} from 'shared/ReactTypes';
1011
import type {Fiber} from './ReactInternalTypes';
1112
import type {SuspenseInstance} from './ReactFiberHostConfig';
1213
import type {Lane} from './ReactFiberLane';
@@ -17,6 +18,16 @@ import {
1718
isSuspenseInstanceFallback,
1819
} from './ReactFiberHostConfig';
1920

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+
2031
// A null SuspenseState represents an unsuspended normal Suspense boundary.
2132
// A non-null SuspenseState means that it is blocked for one reason or another.
2233
// - A non-null dehydrated field means it's blocked pending hydration.

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.