Skip to content

Rule to prevent shareReplay({ refCount: false }) before takeUntil #108

@JasonWeinzierl

Description

@JasonWeinzierl

Putting shareReplay before takeUntil with refCount: false may cause unexpected behavior because the source observable will not be unsubscribed. See the "An update" section in this blog post: https://ncjamieson.com/avoiding-takeuntil-leaks/#an-update . We should implement a new rule that errors on this case.

import { Subject, interval, tap, shareReplay, takeUntil } from 'rxjs';

const destroy = new Subject<void>();
const ticker = interval(1000).pipe(
  tap(value => console.log(value)),
  shareReplay({ refCount: false }),
  takeUntil(destroy),
).subscribe();

destroy.next();

// Despite the takeUntil causing an unsubscribe, the shareReplay remains open and the interval will keep going.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions