-
Notifications
You must be signed in to change notification settings - Fork 44
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
Render when first value changed before mount #91
Render when first value changed before mount #91
Conversation
1bf0b8d
to
674871d
Compare
Thanks for the PR! Introducing To prevent it I think we can give
|
What do you think? @mvgijssel |
Sounds good! To be clear, you want me to keep BehaiourSubject but prevent an unnecessary render by ignoring the initial |
Yes can you update the PR? |
I've updated the PR and the associated tests, but it seems like that adding
doesn't have an impact on the |
I think I know why. After the Suspense re-rendering, the component is re-created, the subscription is also re-established. It's fine with the good old |
Ah yes makes sense! Can you approve the workflow run so we can get this merged? :) |
maybe adding a |
Nope. This will create race condition on multiple components consuming the same observable resource. I'll merge this PR first and see if there are other workarounds for the optimization. |
Fixed it by splitting |
@mvgijssel Could you verify that this is working as expected? Or do you know how to add a test case for this? |
Test added 633498a . |
observable-hooks@4.2.0 published. |
Sorry for the late reply, holidays and such 🎉. But amazing that you got it fixed! I'll install the latest version and see if it works as expected. |
I ran into a race condition using this library in combination with rxfire. The sequence of events:
useObservableSuspense(resource)
resource
returns the first value from the Firestore backendpackages/observable-hooks/src/use-observable-suspense.ts:19
useObservableSuspense
hook will setup a subscription on theshouldUpdate$$
observable atpackages/observable-hooks/src/internal/use-subscription-internal.ts:36
once the component is mounted.The race condition happens with step 5. If the
resource
receives the next piece of data before mounting is completed, theshouldUpdate$$
won't have a listener setup yet and this next piece of data is never rendered in the UI.One way of solving this problem is by using a BehaviourSubject. From the docs
I've also updated the
postinstall
hook to build the code so I can install this fork directly in my project adding the following line to mypackage.json
: