From 8759469384b39a456f79fa59e6622eaabfbe2d63 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Thu, 11 May 2023 00:41:10 -0400 Subject: [PATCH] Lower Suspense throttling heuristic to 300ms Now that the throttling mechanism applies more often, we've decided to lower this a tad to ensure it's not noticeable. The idea is it should be just large enough to prevent jank when lots of different parts of the UI load in rapid sucesssion, but not large enough to make the UI feel sluggish. There's no perfect number, it's just a heuristic. --- packages/react-reconciler/src/ReactFiberWorkLoop.js | 2 +- .../src/__tests__/ReactSuspenseWithNoopRenderer-test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.js b/packages/react-reconciler/src/ReactFiberWorkLoop.js index f6d1d7f7a5849..c558fbd21dca6 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.js @@ -375,7 +375,7 @@ let workInProgressRootRecoverableErrors: Array> | null = // content as it streams in, to minimize jank. // TODO: Think of a better name for this variable? let globalMostRecentFallbackTime: number = 0; -const FALLBACK_THROTTLE_MS: number = 500; +const FALLBACK_THROTTLE_MS: number = 300; // The absolute time for when we should start giving up on rendering // more and prefer CPU suspense heuristics instead. diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js b/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js index fc1aa38708b8d..1b05f8a2f4f50 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js @@ -1863,8 +1863,8 @@ describe('ReactSuspenseWithNoopRenderer', () => { // Advance by a small amount of time. For testing purposes, this is meant // to be just under the throttling interval. It's a heurstic, though, so // if we adjust the heuristic we might have to update this test, too. - Scheduler.unstable_advanceTime(400); - jest.advanceTimersByTime(400); + Scheduler.unstable_advanceTime(200); + jest.advanceTimersByTime(200); // Now resolve B. await act(async () => {