Skip to content

Commit b7bd429

Browse files
arturovtdevversion
authored andcommitted
fix(common): prevent warning about oversize image twice (angular#58021)
I’ve noticed that there was a loop inside a loop. Since we’re already iterating through `images` using `forEach`, it was running a `for` loop through `images` again. This was probably a mistake made when the functionality was initially added. The test actually verified that `logs.length` is `1`, but in the real environment, it logs twice (which is quite obvious due to the code). I’ve also added the missing file to the Bazel target. PR Close angular#58021
1 parent 2225444 commit b7bd429

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

packages/core/src/image_performance_warning.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,10 @@ export class ImagePerformanceWarning implements OnDestroy {
105105
lcpElementLoadedCorrectly = false;
106106
images.forEach((image) => {
107107
if (!this.options?.disableImageSizeWarning) {
108-
for (const image of images) {
109-
// Image elements using the NgOptimizedImage directive are excluded,
110-
// as that directive has its own version of this check.
111-
if (!image.getAttribute('ng-img') && this.isOversized(image)) {
112-
logOversizedImageWarning(image.src);
113-
}
108+
// Image elements using the NgOptimizedImage directive are excluded,
109+
// as that directive has its own version of this check.
110+
if (!image.getAttribute('ng-img') && this.isOversized(image)) {
111+
logOversizedImageWarning(image.src);
114112
}
115113
}
116114
if (!this.options?.disableImageLazyLoadWarning && this.lcpImageUrl) {

packages/core/test/bundling/image-directive/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ http_server(
4646
"e2e/a.png",
4747
"e2e/b.png",
4848
"e2e/logo-1500w.jpg",
49+
"e2e/logo-1500w.svg",
4950
"e2e/logo-500w.jpg",
5051
"e2e/white-607x3.png",
5152
"index.html",

0 commit comments

Comments
 (0)