angular: Control flow with defer inside does not clean up before httpClient ends its request
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
Yes
Description
Hi. I noticed that defer’s @loading block is not cleaned up before HttpClient completes its request. In v17 it doesn’t wait for it. Demo video:
https://github.com/user-attachments/assets/5d4566c8-68d3-4a64-8c47-cf09ae639a75
Full component code which reproduces the issue:
import {Component, inject, PLATFORM_ID, signal} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {isPlatformServer} from "@angular/common";
import {LoggedCmp} from "./logged-cmp";
import {TestCmp} from "./test-cmp";
import {User} from "./types";
@Component({
selector: 'app-home-cmp',
standalone: true,
imports: [
LoggedCmp,
TestCmp
],
template: `
@if (user()) {
<p>
@defer (when user()) {
<app-logged-cmp [user]="user()!" />
}
</p>
} @else {
<div>
@defer (on immediate) {
<app-test-cmp />
} @loading {
<div>Loading....</div>
} @placeholder {
<div>Loading....</div>
}
</div>
}
`
})
export class HomeCmp {
private readonly httpClient = inject(HttpClient);
private readonly platformId = inject(PLATFORM_ID);
user = signal<User | null>({id: 1, nickname: 'admin'});
constructor() {
if (isPlatformServer(this.platformId)) {
this.user.set(null);
} else {
this.httpClient.get(`https://dummyjson.com/RESOURCE/?delay=5000&t=${ Date.now() }`)
.subscribe();
}
}
}
Please provide a link to a minimal reproduction of the bug
https://github.com/zip-fa/ng18-defer-cleanup-issue
Please provide the exception or error you saw
"Loading..." block is not removed from DOM-tree before HttpClient completes request
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 18.1.0
Node: 22.4.1
Package Manager: npm 10.8.1
OS: darwin arm64
Angular: 18.1.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router, ssr
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1801.0
@angular-devkit/build-angular 18.1.0
@angular-devkit/core 18.1.0
@angular-devkit/schematics 18.1.0
@schematics/angular 18.1.0
rxjs 7.8.1
typescript 5.4.5
zone.js 0.14.7
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 19 (9 by maintainers)
Waiting to try v19 then 🙏🏻 Will update this issue if v19 is enough, thanks guys
That is correct @AndrewKushnir.
Sure thing! Will try new version tomorrow early