Skip to content

React 18 - waterfall suspensions re-trigger the Suspense boundary  #22626

Open
@arackaf

Description

@arackaf

I'm seeing some baffling behavior with React 18 in concurrent mode. The minimal repro is below. The tl;dr is this:

I have a single Suspense boundary at the root of the application. The fallback turns the screen pink (so you know it's there).

Problem 1

I load some data with a Suspense hook. When the data come back, and render, subsequent Suspensions will happen, since I have a SuspenseImg component which suspends while each image preloads.

Expected Behavior

The fallback should show until the data come in, and all of the subsequent image preloads are done.

Actual Behavior

The fallback shows, then the page renders briefly, without data, and then re-suspends while the images preload.


Problem 2

There's a button which loads more data, using startTransition. The data load re-triggers the same suspension, and the new data cause the same suspensions when rendered, via the same SuspenseImg (I force it to suspend even though I'm loading the same 5 images over and over).

Expected Behavior

The loading boolean from useTransition should show until the data are returned, and all of the images have pre-loaded

Actual Behavior

The loading boolean shows while the data are loading, and then the main fallback shows while the images preload.


I'll assume this isn't a bug, and that I instead have misunderstood how this works. I had thought Suspense was supposed to make this stuff fire and forget, with React keeping the appropriate fallback / loading boolean set until the entire state has been set, and everything rendered without anything suspending. But it seems I've misunderstood something?


https://codesandbox.io/s/suspense-debug-pz5mz?file=/src/useQuery.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    React 18Bug reports, questions, and general feedback about React 18Type: Discussion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions