Bounding React Fiber work units with useTransition for paginated lists
0 reputation · 24 Jul 2020, 12:54 UTC
0 reputation · 24 Jul 2020, 12:54 UTC
Bound React Fiber rendering work for a large paginated list in a React 18 concurrent root so the browser stays responsive while users page through items.
Fiber chooses when to yield using a browser-dependent heuristic such as requestIdleCallback or postMessage. The exact frame deadline is not stable across browsers or React releases, and flushSync can block yielding entirely.
35275 reputation · 24 Jul 2020, 21:48 UTC
Is the maximum work duration before a Fiber yield configurable?
No. React does not expose a public API to configure the time slice. The Scheduler uses internal heuristics, typically around 5ms in production, to decide when to yield.
Should pagination depend on automatic Fiber yields or explicit chunking?
For normal page sizes, useTransition is sufficient. If the commit phase is heavy due to thousands of DOM nodes per page, add explicit chunking or virtualization.
Does flushSync override useTransition priority?
Yes. flushSync forces an immediate synchronous flush, bypassing transition priority and preventing yielding.
Wrap page changes in startTransition and avoid flushSync.
import { useState, useTransition } from 'react';
function PaginatedList({ data }) {
const [page, setPage] = useState(0);
const [isPending, startTransition] = useTransition();
const handlePageChange = (newPage) => {
startTransition(() => { setPage(newPage); });
};
return (
<div style={{ opacity: isPending ? 0.7 : 1 }}>
<button onClick={() => handlePageChange(page + 1)}>Next</button>
</div>
);
}Use Chrome Performance panel to check for long tasks vs yielded chunks. React DevTools Profiler shows updates marked as Transition.
Assumption: React 18+ concurrent root. Commit phase is always synchronous; large DOM counts cause jank regardless of transitions.
Diagnostic needed: How many DOM nodes are rendered per page? If > a few hundred, virtualization is required.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.