Content-Length: 311297 | pFad | https://github.com/angular/angular/commit/efda8724535a8560a64b28cc2bf81df5931af686

1A fix(common): prevent reading chunks if app is destroyed (#61354) · angular/angular@efda872 · GitHub
Skip to content

Commit efda872

Browse files
arturovtthePunderWoman
authored andcommitted
fix(common): prevent reading chunks if app is destroyed (#61354)
Prevents processing response chunks after the application has been destroyed. PR Close #61354
1 parent c43fd3a commit efda872

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/common/http/src/fetch.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {inject, Injectable, InjectionToken, NgZone} from '@angular/core';
9+
import {ApplicationRef, inject, Injectable, InjectionToken, NgZone} from '@angular/core';
1010
import {Observable, Observer} from 'rxjs';
1111

1212
import {HttpBackend} from './backend';
@@ -73,6 +73,7 @@ export class FetchBackend implements HttpBackend {
7373
private readonly fetchImpl =
7474
inject(FetchFactory, {optional: true})?.fetch ?? ((...args) => globalThis.fetch(...args));
7575
private readonly ngZone = inject(NgZone);
76+
private readonly appRef = inject(ApplicationRef);
7677

7778
handle(request: HttpRequest<any>): Observable<HttpEvent<any>> {
7879
return new Observable((observer) => {
@@ -152,6 +153,14 @@ export class FetchBackend implements HttpBackend {
152153
// Here calling the async ReadableStreamDefaultReader.read() is responsible for triggering CD
153154
await this.ngZone.runOutsideAngular(async () => {
154155
while (true) {
156+
// Prevent reading chunks if the app is destroyed. Otherwise, we risk doing
157+
// unnecessary work or triggering side effects after teardown.
158+
// This may happen if the app was explicitly destroyed before
159+
// the response returned entirely.
160+
if (this.appRef.destroyed) {
161+
break;
162+
}
163+
155164
const {done, value} = await reader.read();
156165

157166
if (done) {

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/angular/angular/commit/efda8724535a8560a64b28cc2bf81df5931af686

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy