Skip to content

BehaviorSubject.getValue() always returns initial value if subscribed to observable from Webpack library #5105

@es-repo

Description

@es-repo

Bug Report

Current Behavior

BehaviorSubject.getValue() always returns initial value if subscribed to an observable from Webpack library while the observable is emitting new values.

Reproduction

-Minimum code which reproduces bug:
https://github.com/es-repo/bug-repro/tree/master/rxjs/behavior-subject-and-observable-from-lib

Run "npm start" from within the "app" folder or open this link https://es-repo.github.io/bug-repro/rxjs/behavior-subject-and-observable-from-lib/app/dist/. And open console.

Code from the "app" which reproduces the issue:

import { BehaviorSubject, interval } from 'rxjs';
import createObservable from 'lib';

const subject1 = new BehaviorSubject(undefined);
createObservable().subscribe(subject1);

const subject2 = new BehaviorSubject(undefined);
interval(1000).subscribe(subject2);

subject1.subscribe(v => {
  console.log(`Observable from lib: value=${v} getValue()=${subject1.getValue()}`);
});

subject2.subscribe(v => {
  console.log(`Observable from app: value=${v} getValue()=${subject2.getValue()}`);
});

Code from the "lib":

import { interval } from 'rxjs';

export default function createObservable() {
  return interval(1000);
}

Console output:

Observable from lib: value=undefined getValue()=undefined
Observable from app: value=undefined getValue()=undefined
Observable from lib: value=0 getValue()=undefined
Observable from app: value=0 getValue()=0
Observable from lib: value=1 getValue()=undefined
Observable from app: value=1 getValue()=1
...

Expected behavior

BehaviorSubject.getValue() should return last value emitted from Observable.

Environment

  • Runtime: Node v12.7.0, Chrome v78
  • RxJS version: 6.5.3
  • Webpack: 4.41.2

Additional context

Related issue: #5051

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions