Is there a way to make React's startTransition not wait for Suspense?

Is there a way to make React's startTransition not wait for Suspense?

  

As far as I know, if an update inside startTransition causes components to suspend, React would wait for those components to unsuspend before completing the transition. However, I don't want React to do that. I'm using startTransition just for time slicing, I don't think it's good UX to wait for suspense to complete before transitioning. I'm trying to find a way to get it to transition asap when there are suspended components.

E.g. I could have a modal and the modal content is loaded using suspense. With the current React behavior, when you click a button to open the modal, React would wait for the modal content to fully load before showing the modal. Instead, I'd want an empty modal to appear as soon as you click the button. Then, it would wait for the modal content to load.

Is there a way to either:

  1. make startTransition not wait for the suspended component OR
  2. enable time slicing without startTransition

Demo of transitions waiting for suspense: here

Answer

No. There is no way to do this currently.

The React concurrent primitives don't distinguish between the next render waiting for a Suspended component to be ready or a time-sliced tree.

© 2024 Dagalaxy. All rights reserved.