Skip to content

shareReplay with refCount stops working #6760

@ghostlytalamaur

Description

@ghostlytalamaur

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

7.5.1
6.4.0

Version

7.5.1

Environment

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions