Open yatsuna827 opened 3 weeks ago
Furthermore, I have investigated a few more examples. When using a class like Recoil's Loadable
instead of the use
API, this issue does not occur.
And by wrapping Loadable
and use
in the same Suspense
, the strange behavior of use
becomes clear. When multiple Promises
are thrown within a single Suspense
, it seems that all Suspense
boundaries are halted until the Promise
thrown by use
is resolved. This does not seem like the intended behavior to me.
https://codesandbox.io/p/sandbox/use-and-suspense-forked-skjk48
2 Suspense boundaries is sufficient to reproduce this behavior: https://codesandbox.io/p/sandbox/crazy-browser-88t26y?file=%2Fsrc%2Findex.js%3A7%2C1
Flagged this internally to check if it's intended or not.
Summary
https://codesandbox.io/p/sandbox/use-and-suspense-hlcjk6
The two components
<Expected>
π and<Unexpected>
π€ are expected to behave in the same way. That is, No.1 to No.3 should be displayed one second apart, and No.4 and No.5 should be displayed two seconds after No.3 is displayed.There is a difference in the waiting time for No.4 between
<Expected>
and<Unexpected>
, being 4 seconds or 3 seconds, but since they are wrapped together in<Suspense>
with No.5, they should be throttled and displayed after 5 seconds.However, in
<Unexpected>
, not only that, but No.3, which should belong to a different<Suspense>
scope, is also displayed after 5 seconds. This seems to break the behavior of<Suspense>
.Please note that this is a different issue from the one being discussed in https://github.com/facebook/react/pull/26380. I am issuing a Promise outside of Suspense and passing it as props.