Skip to content

Commit c1312da

Browse files
SkyZeroZxleonsenft
authored andcommitted
fix(common): avoid redundant image fetch on destroy with auto sizes
prevents browsers from re-fetch image during DOM teardown when using `sizes="auto"` with lazy loading. Fixes #67055
1 parent a73b4b7 commit c1312da

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/common/src/directives/ng_optimized_image/ng_optimized_image.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,15 @@ export class NgOptimizedImage implements OnInit, OnChanges {
406406
}
407407
});
408408
}
409+
410+
// Browsers might re-evaluate the image during DOM teardown when using `sizes="auto"`
411+
// with `loading="lazy"`, potentially triggering an unnecessary image fetch.
412+
// This is expected behavior per the HTML spec
413+
// See: https://html.spec.whatwg.org/multipage/images.html#sizes-attributes
414+
// See also: https://github.com/angular/angular/issues/67055#issuecomment-3898513831
415+
this.destroyRef.onDestroy(() => {
416+
this.renderer.removeAttribute(this.imgElement, 'loading');
417+
});
409418
}
410419

411420
/** @docs-private */

0 commit comments

Comments
 (0)