-
-
Notifications
You must be signed in to change notification settings - Fork 380
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
Fix redundant suspense on hydration #516
Conversation
If there are any reasons why cache was not updated in |
I am pretty sure that the "proper" fix would be to move That would prevent this issue from happening from a |
I don’t see how your proposal will fix the issue. The problem is that after |
2 lines below your changes (:136) if (options.suspense) { // your change
this.setCache(result)
}
this.state.result = result
this.state.loading = false; <--- explicitly set loading to false Rule is simple - if you are not |
Aha! I see now. Thank you. I’ll try it out and update PR if everything works as intended. |
Great suggestion. It works this way. No flickering and everything seems to load correctly. |
I’ve just thought of another issue I’ve noticed: errors were not thrown in most cases with suspense enabled (missing default export, module evaluation problems) and now they appear as they should since |
Oh, that's good news from one point of view, and a breaking change from another (even if all tests 😅 are green). So this time we created another problem for ourselves - 🤓 Sorry mate, look like your initial approach would cause fewer fixes, not requiring to rewrite entire Probably it's better to merge the first version, to mitigate the problem, and only then refactor everything. @gregberge - is it sounds reasonable? |
I don’t see the problem and I don’t see how this is the breaking change. Can you elaborate? As I see it... If suspense is disabled, everything works exactly the same as before. If suspense is enabled, it works the same as non-suspense but with suspending the tree instead of using given fallback. |
|
`loadSync` does not update cache thus suspense kicks in during hydration, which causes flash of loader. This fix ensures cache is updated when `loadSync` is called if suspense is used to keep hydration as smooth as possible.
bc0086c
to
7f7c8ee
Compare
I pushed back the first version as you requested. |
The cache isnt persisted, so... When you jump to rehydration on the client side I believe you Will find yourself with an empty cache, hence throwing the promise again and suspending, no? |
This should be part of the refactoring to make Suspense work correctly. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Summary
loadSync
does not update cache thus suspense kicks in during hydration, which causes flash of loader. This fix ensures cache is updated whenloadSync
is called if suspense is used to keep hydration as smooth as possible.Test plan
Meanwhile it will be tested in one of my company’s codebases to see if the change causes any regressions, but as I understand it will not cover all possible scenarios.