shareReplay with refCount stops working
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 31.7k
- Forks
- 3k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
When subscribe to shared observable multiple times internal connection to the source observable gets broken. It stops emit values on subscribe.
Expected behavior
Expected output:
first: 7.5.1
second: 7.5.1
Actual output
first: 7.5.1
Reproduction code
import { BehaviorSubject, merge, of, Subject } from 'rxjs';
import {
shareReplay,
take,
takeUntil,
materialize,
filter,
} from 'rxjs/operators';
const shared$ = new BehaviorSubject('7.5.1').pipe(
shareReplay({ refCount: true, bufferSize: 1 })
);
const isCompleted$ = shared$.pipe(
materialize(),
filter((n) => n.kind === 'C'),
take(1)
);
const work = new Subject().pipe(takeUntil(isCompleted$));
merge(work, shared$)
.pipe(take(1))
.subscribe((value) => console.log('first: ', value));
shared$.subscribe((value) => console.log('second:', value));
Reproduction URL
Version
7.5.1
Environment
No response
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided reproduction using shareReplay({ refCount: true, bufferSize: 1 }) and compare its behavior in the linked 7.5.1 and 6.4.0 examples. The fix should preserve the source connection so both subscriptions produce the expected first and second values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100