question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

switchMap not unsubscribing depending on import of Observable

See original GitHub issue

RxJS version: 5.5.6

In our app, we today encountered an issue with code which is essentially the same as the following.

[Removed in favor of the repository with a reproducable version posted below]

The behavior we saw was that all the (temporarily) started timers kept executing in parallel, as if switchMap didn’t unsubscribe from it when id$ emitted.

After a lot of debugging, I eventually figured out that the bug only arises when Observable is imported as

import { Observable } from "rxjs";

but not when imported as

import { Observable } from "rxjs/Observable";

Unfortunately, I cannot reproduce the issue on Stackblitz independently of how I import. My feeling here is that there is some dependency which patches Observable, perhaps with an older, faulty version or something.

However, the problem I am having with this theory: I would think that in this case it breaks when importing from rxjs/Observable, but not when importing rxjs. But what we see is exactly the opposite.

I realize that with rxjs 5.5.0, patching Observable isn’t the choice of things anymore and we do intend to move away from this. In the mean time, I would really like to understand how importing from rxjs breaks behavior so drastically and would appreciate any ideas on how to figure out what is messing with us here.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kayjteacommented, Feb 20, 2018

Reproduce steps:

https://github.com/kayjtea/rxjs3306

The problem arises from mixing the full RxJS import with the patch mechanism.

0reactions
lock[bot]commented, Jun 5, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RxJS 6: switchMap not unsubscribing depending on import of ...
switchMap () should properly unsubscribe the previous observable before subscribing to the next one. After changing the imports (see below), ...
Read more >
Unsubscribe Nested Observable when outer observable is false
You can use switchMap to unsubscribe from the previous subscription and NEVER to skip when checkbox is disable import { NEVER } from...
Read more >
Switching to the Most Recent Observable with switchMap
First, import the Router, ActivatedRoute, and ParamMap tokens from the router package. Then, import the switchMap operator because you will need ...
Read more >
RxJs SwitchMap Operator: How Does It Work?
When the source emits a new value, it will create a new inner observable and switch to those values instead. What gets unsubscribed...
Read more >
switchMap - Learn RxJS
switchMap could cancel a request if the source emits quickly enough. In these scenarios mergeMap is the correct option.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found