Skip to content

Topics

Jump to a topic.

Search questions

Find a question by title, tag, or summary.

How do transitions stop Suspense from showing a fallback again?

Questions in this chapter (5)
  • Draft
  • hard
  • Askedoften
  • Verified October 2026

Answer

Suspense decides what to show when something suspends, and the kind of update decides which outcome React accepts:

  • Urgent update (a plain setState from a click): the user expects an immediate response, so React commits right away. If a boundary that's already showing content suspends, React hides that content and shows the fallback again. Navigating with a boundary near the root swaps the whole page for a spinner.
  • Transition (startTransition, useTransition): the update is allowed to wait. If committing it would hide already-revealed content behind a fallback, React doesn't commit. The old UI stays on screen and interactive, and the new UI appears once the data has loaded. With useTransition, isPending is true meanwhile, so you can dim the page or show a progress bar.
  • useDeferredValue: the background re-render with the new value is a Transition too. If it suspends, the user keeps seeing the stale value instead of a fallback.

Two limits matter:

  1. New boundaries still show their fallbacks. A Transition only waits long enough not to hide what's already on screen. A <Suspense> that appears for the first time in this update shows its fallback immediately, so the new page can render its shell while its slower sections load.
  2. Different content should reset. When the user navigates to another profile, the old profile staying visible may be wrong. Give the boundary (or a parent) key={userId}: a new key makes it a new boundary, so it shows its fallback even in a Transition.

Only non-urgent updates get this treatment; React never delays an urgent render. That's why Suspense-enabled routers wrap navigations in Transitions by default, and why refetching with use stores the new promise in state inside startTransition.

Example

function Bio({ user }) {
  const bio = use(fetchBio(user)); // cached per user; resolves after 300 ms
  useLayoutEffect(() => console.log('show', bio), [bio]);
  return <p>{bio}</p>;
}
function Spinner() {
  useLayoutEffect(() => console.log('show spinner'), []);
  return <p>Loading…</p>;
}
function Profile() {
  const [user, setUser] = useState('ann');
  const [isPending, startTransition] = useTransition();
  useLayoutEffect(() => console.log('commit', user, isPending));
  return (
    <>
      <button onClick={() => startTransition(() => setUser('bob'))}>Bob</button>
      <Suspense fallback={<Spinner />}><Bio user={user} /></Suspense>
    </>
  );
}
// → commit ann true
// → show bob's bio
// → commit bob false
// With <Suspense key={user} …>:
// → commit ann true
// → show spinner
// → commit bob false
// → show bob's bio

Logged after clicking Bob once Ann's bio was showing. Chrome 156 and Firefox 159, development and production builds of React 19.3.1. Without the key, Ann's bio stayed on screen for 300 ms while isPending was true; with it, the spinner replaced Ann's bio at once. With a plain setUser, the spinner showed in both versions.

Pitfalls

  • Navigating with a plain setState. Every already-revealed boundary that suspends flashes back to its fallback; mark navigations as Transitions.
  • Expecting a Transition to wait for everything. A nested boundary that's new on the next page shows its fallback; only boundaries already showing content are protected.
  • Forgetting a pending indicator. The old page stays put with no feedback until the data arrives; there's no timeout, and in a test a 5-second request kept the old page for 5 seconds. Use isPending.
  • Fetching nested data only when its component renders. In a Transition that reset the boundary with key, React 19.3.1 didn't pre-render a nested section, so its request started only after the outer data arrived, 200 ms later. Start requests in the event handler.

Follow-ups

useTransition or useDeferredValue here?
The docs suggest Transitions for navigation, usually inside the router, and useDeferredValue in application code where one part of the UI may lag, such as search results under an input that must stay urgent.
Can the user keep interacting while the Transition waits?
Yes. In a test, a counter click 200 ms into a pending navigation committed at once, over the old page with isPending still true; the navigation committed 300 ms later, keeping the new count.
Why does a new boundary show its fallback even in a Transition?
Nothing was visible there, so showing a fallback hides nothing. Waiting for it would block the whole navigation on the slowest section.

Exercises

What does the user see, and when?

function ArtistPage() {
  return (
    <>
      <Biography />  {/* data takes 200 ms */}
      <Suspense fallback={<p>albums loading</p>}>
        <Albums />   {/* data takes 1,000 ms */}
      </Suspense>
    </>
  );
}

<Suspense fallback={<p>page loading</p>}>
  <button onClick={() => startTransition(() => setPage('artist'))}>Open</button>
  {page === 'index' ? <p>index</p> : <ArtistPage />}
</Suspense>

Comments

Comments are GitHub Discussions: you sign in with GitHub to post or react.