Suspense ping shouldn't suspend if all suspended content is already in fallback mode
See original GitHub issueWhen using suspense and hooks - specifically useState
and useEffect
- nested async renders (using react-cache
) cause state hooks not to be updated. Specifically this happens between the first promise settling and the last promise settling in a Suspense
component. However the state updates concerned can be outside of the Suspense
root: https://codesandbox.io/s/wznnxz9pvw
In the linked example, moving the mouse will update the displayed coordinates for the first 2000ms (the time at which the first thrown promise resolves) however, after this the UI will not show any updated coordinates until after the final nested promise in the adjacent Suspense
root settles.
I may both be using Suspense wrong (given the understandable lack of documentation) as I’ve been having other bugs with this setup, specifically the above example will sometimes never render beyond the “loading …” placeholder. This is especially noticeable with setting higher timeouts in the Timeout
component.
react 16.7.0-alpha react-dom 16.7.0-alpha react-cache 2.0.0-alpha
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
@aweary ah that makes sense, I guess in that instance there’s no real state to update anywhere as the state change has happened outside React (in the cache). So pinging is just a way of forcing another render with the newly fetched resource in the cache 👌🏻
@RichieAHB a “real update” is just a regular update that occurs when you update state. I believe a ping occurs when the Promise that was thrown for a suspended components resolves or rejects, “pinging” React so that it knows to try rendering again.
@gaearon is that right?