Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Multiple subscribers to ApplicationRef.isStable should all… #53541

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/core/src/application/application_ref.ts
Expand Up @@ -10,7 +10,7 @@ import '../util/ng_jit_mode';

import {setThrowInvalidWriteToSignalError} from '@angular/core/primitives/signals';
import {Observable, of} from 'rxjs';
import {distinctUntilChanged, first, share, switchMap} from 'rxjs/operators';
import {distinctUntilChanged, first, switchMap} from 'rxjs/operators';

import {getCompilerFacade, JitCompilerUsage} from '../compiler/compiler_facade';
import {Console} from '../console';
Expand Down Expand Up @@ -351,7 +351,6 @@ export class ApplicationRef {
.hasPendingTasks.pipe(
switchMap(hasPendingTasks => hasPendingTasks ? of(false) : this.zoneIsStable),
distinctUntilChanged(),
share(),
);

private readonly _injector = inject(EnvironmentInjector);
Expand Down
9 changes: 9 additions & 0 deletions packages/core/test/application_ref_spec.ts
Expand Up @@ -21,6 +21,7 @@ import type {ServerModule} from '@angular/platform-server';
import {ApplicationRef} from '../src/application/application_ref';
import {NoopNgZone} from '../src/zone/ng_zone';
import {ComponentFixtureNoNgZone, inject, TestBed, waitForAsync, withModule} from '../testing';
import {take} from 'rxjs/operators';

let serverPlatformModule: Promise<Type<ServerModule>>|null = null;
if (isNode) {
Expand Down Expand Up @@ -795,6 +796,14 @@ describe('AppRef', () => {
expectStableTexts(MacroMicroTaskComp, ['111']);
}));

it('isStable can be subscribed to many times', async () => {
const appRef: ApplicationRef = TestBed.inject(ApplicationRef);
// Create stable subscription but do not unsubscribe before the second subscription is made
appRef.isStable.subscribe();
await expectAsync(appRef.isStable.pipe(take(1)).toPromise()).toBeResolved();
stableCalled = true;
});

describe('unstable', () => {
let unstableCalled = false;

Expand Down
Expand Up @@ -1406,9 +1406,6 @@
{
"name": "setupStaticAttributes"
},
{
"name": "share"
},
{
"name": "shareSubjectFactory"
},
Expand Down
Expand Up @@ -1478,9 +1478,6 @@
{
"name": "setupStaticAttributes"
},
{
"name": "share"
},
{
"name": "shareSubjectFactory"
},
Expand Down
Expand Up @@ -1178,9 +1178,6 @@
{
"name": "setupStaticAttributes"
},
{
"name": "share"
},
{
"name": "shareSubjectFactory"
},
Expand Down
3 changes: 0 additions & 3 deletions packages/core/test/bundling/defer/bundle.golden_symbols.json
Expand Up @@ -2336,9 +2336,6 @@
{
"name": "setupStaticAttributes"
},
{
"name": "share"
},
{
"name": "shareSubjectFactory"
},
Expand Down
Expand Up @@ -1649,9 +1649,6 @@
{
"name": "setupStaticAttributes"
},
{
"name": "share"
},
{
"name": "shareSubjectFactory"
},
Expand Down
Expand Up @@ -1625,9 +1625,6 @@
{
"name": "setupStaticAttributes"
},
{
"name": "share"
},
{
"name": "shareSubjectFactory"
},
Expand Down
Expand Up @@ -932,9 +932,6 @@
{
"name": "setUpAttributes"
},
{
"name": "share"
},
{
"name": "shareSubjectFactory"
},
Expand Down
Expand Up @@ -1280,9 +1280,6 @@
{
"name": "setUpAttributes"
},
{
"name": "share"
},
{
"name": "shareSubjectFactory"
},
Expand Down
3 changes: 0 additions & 3 deletions packages/core/test/bundling/router/bundle.golden_symbols.json
Expand Up @@ -1970,9 +1970,6 @@
{
"name": "shallowEqual"
},
{
"name": "share"
},
{
"name": "shareSubjectFactory"
},
Expand Down
Expand Up @@ -1031,9 +1031,6 @@
{
"name": "setUpAttributes"
},
{
"name": "share"
},
{
"name": "shareSubjectFactory"
},
Expand Down
3 changes: 0 additions & 3 deletions packages/core/test/bundling/todo/bundle.golden_symbols.json
Expand Up @@ -1418,9 +1418,6 @@
{
"name": "setupStaticAttributes"
},
{
"name": "share"
},
{
"name": "shareSubjectFactory"
},
Expand Down