-
Notifications
You must be signed in to change notification settings - Fork 47.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suspense fallback remounts when each child resolves #14073
Comments
Looks like expected behavior to me, However, in Concurrent Mode the observed behaviour aligns with your expected behaviour, with one apparent bug: the children don't render when |
Here is a slightly less contrived example than what I shared above Here there is a CSS loading spinner, due to the remounting of the fallback component the animation of the spinner is not smooth. |
Seems like a bug. |
I added a failing test in #14078. Not sure if this is a bug or unavoidable quirk in sync mode. |
Thanks 👍 |
Has this been fixed? I'm seeing the same issue now with React 17.0.1 |
That one was fixed, so you're seeing something different. File a bug with a minimal repro case. |
Actually, in my case, I have a Suspense (call it SuspenseB) nested several levels below another Suspense (call it SuspenseA). For SuspenseA still renders its fallback UI when an async component is loaded within SuspenseB, but only if I do not provide a fallback for SuspenseB. In my case I did not want any fallback UI for B at all. So, I ended up providing a {null} fallback and everything worked as desired. Is what I just described by design? If not, I can go ahead and write up another bug... |
Hmm. I'm not sure I understand what the expected and the actual behavior was. |
@gaearon - The expected behavior (for me, at least) was to not show the fallback from SuspenseA, since the direct child components of SuspenseA were already loaded. So (psuedoish React code):
In my case, showing SuspenseA's fallback when AysncComponentB was loaded was unexpected. I assumed that since AysncComponentA already loaded there would be no more fallback showing at that level. (I can create a CodeSandbox if you'd like, just pressed for time today...) |
I think the issue here is that We'll need to revisit the behavior (maybe it should always warn and tell you to specify it). But the idea definitely isn't that |
@gaearon - Thanks for the quick reply. I would expect SuspenseB to behave like SuspenseA for its child components. So, if I don't provide a fallback, don't show one. IMO, React can't really make too many assumptions on what the best practices for loading states are for individual projects ;) |
If that's the behavior you want, you can always pass |
It might be nice to just call out the behavior in the React official docs. |
Yeah. The undefined fallback thing seems like it's accidental so we'll revisit that. |
Do you want to request a feature or report a bug?
Not sure if its a bug or a feature request.
What is the current behavior?
The component given as a fallback to Suspense is remounted each time a lazy child resolves.
https://codesandbox.io/s/z6v6x3n1np
This example shows how a fallback component, which counts up, is mounted more than once.
What is the expected behavior?
The fallback is mounted once and is only unmounted when all lazy children are resolved.
In the example the counter would run up to 9.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
react@16.6.0
The text was updated successfully, but these errors were encountered: