Ensure unsubscribing only removes a single subscription #1315
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In our scheduling/calendar app, we subscribe for events in a given location, but we allow you to pass in a date filter, which we use in a custom resolver which allows us to limit what you receive to just the date you're looking. It looks something like this:
As you navigate between days in the calendar, our React state seems to start the new subscription before unsubscribing from the previous one.
The code added/modified here seems to then cause the Registry to get rid of both subscriptions and no more events are sent to the frontend.
I confirmed that by logging what is in the Registry at each step:
Registry keys after the first subscription:
Registry keys after the second subscription:
Registry keys after unsubscribing once:
This looks like an invalid subscription since it no longer has the topic definition.
Just removing those 3 lines fixes the issues and I managed to replicate it in a test (omitted the custom resolver we have since it seems unnecessary for this example) and seemingly everything else passes, but I'm not entirely sure what the original code wanted to achieve.
Appreciate any feedback and guidance!