-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Unsubscription doesn't work after shareReplay?! #3034
Comments
I'm unable to reproduce this with the script that's in the issue. Well after two seconds has elapsed, clicking on the |
Yes, that's a problem.
Yes and I believe it's a bug because Documentation on the
This is from v4 (can't find the same doc piece for v5, but that didn't change I guess). In my example we have 0 subscriptions after 2 second and |
According to this PR, what you are seeing is the intended behaviour. |
Ok, I'll give a few additional info. I'm making a multipage app. Each page has it's own set of listeners. Listeners from one page obviously should not interact with the listeners from the other page. Which is managed by subscription / unsubscription. Now unsubscription doesn't work so I'll keep receiving events from "inactive" page which is weird and broken. If replayed sources does not take I think it's pretty clear why unremovable event listeners are inappropriate. Memory leaks and repeating events are just some of the problems they bring.
So I still think of it as a bug. If that is considered a desired behavior – please tell me some workarounds. My first example was made up as a "simplest non-working case". Most of the time you let intents = {
click: fromDOMEvent(...)
}
// 100 lines below
let state = O.merge(intents.click ...)
.scan(...)
.shareReplay(1) // makes intents.click addEventListener unremovable |
Given that the observable created with The implementation that preceded the referenced PR, was essentially the same, but included some special handling for sources that completed - which is not relevant here. As far as I am aware, there is no documentation for |
https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md says
which works (as well as your snippet above). So, on the one hand, it's my fault of missing this doc piece, on the other – I can't get if |
|
Then why migration guide RX4 -> RX5 mentions it? And I certanly used it previously: https://github.com/ivan-kleshnin/cyclejs-examples/blob/master/package.json#L32 Perhaps it was re-added to Rx5 in that PR. Anyway, thanks for helping me! |
I've run into this problem. In my opinion it is very strange that the subscription (to the source) can leak even if there is no subscriber (on the shareReplay) anymore. If the already given examples aren't enough then I can also add my use case where this kind of behavior is present as a bug. |
@fjozsef Apparently it is intended per this bugfix. I have also run into this problem. In our application we use the shareReplay() operator to prevent re-evaluation of the source observable (an expensive http-get) which has multiple subscribers. The change in behavior between RX4 and RX5 now causes a ObjectUnsubscribedError in multiple parts of our application. Please reinstate the part in the migration guide where it is advised that shareReplay is replaced with pusblishReplay().refCount(), or at least make a specific note of it somewhere. This is definitely a breaking change, even if it was an unintended side-effect before. |
Just use a custom operator, it's dead simple export const weakShareReplay = <T>(bufferSize?: number, windowTime?: number ) =>
(source: Observable<T>) =>
source.pipe(publishReplay(bufferSize, windowTime), refCount()); @benlesh this could be added to the library, maybe? |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
RxJS version: 5.5.2
Code to reproduce:
Expected behavior:
Both buttons stop working after two seconds.
Actual behavior:
Only the first button stop working after two seconds.
The text was updated successfully, but these errors were encountered: