Skip to content

fix(common): avoid redundant image fetch on destroy with auto sizes#67060

Merged
leonsenft merged 1 commit intoangular:mainfrom
SkyZeroZx:fix/img-directive-refetch
Mar 19, 2026
Merged

fix(common): avoid redundant image fetch on destroy with auto sizes#67060
leonsenft merged 1 commit intoangular:mainfrom
SkyZeroZx:fix/img-directive-refetch

Conversation

@SkyZeroZx
Copy link
Copy Markdown
Contributor

Prevents Chromium from re-fetch image during DOM teardown when using sizes="auto" with lazy loading.

See #67055 (comment)

Fixes #67055

@angular-robot angular-robot bot added the area: common Issues related to APIs in the @angular/common package label Feb 13, 2026
@ngbot ngbot bot added this to the Backlog milestone Feb 13, 2026
@SkyZeroZx SkyZeroZx marked this pull request as ready for review February 13, 2026 19:58
@pullapprove pullapprove bot requested a review from JeanMeche February 13, 2026 19:58
@JeanMeche
Copy link
Copy Markdown
Member

As mentionned in #67055, I think if we workaround around a chrome bug, we should at least reference a chrome bug reference.

});
}

// Chromium may re-evaluate during DOM teardown when using `sizes="auto"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to update the phrasing to hint that this is more or less the expected behavior per the specs.
Maybe the other browsers will allign in the future.

Also I'm wondering if we can catch this behavior in a unit test with the onLoad event.

Copy link
Copy Markdown
Contributor Author

@SkyZeroZx SkyZeroZx Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wdyt ?

    // Browsers might re-evaluate the image during DOM teardown when using `sizes="auto"`
    // with `loading="lazy"`, potentially triggering an unnecessary image fetch.
    // This is expected behavior per the HTML spec
    // See: https://html.spec.whatwg.org/multipage/images.html#sizes-attributes
    // See also: https://github.com/angular/angular/issues/67055#issuecomment-3898513831

I tried to reproduce the problem in a unit test with the onload event, but it was not possible ( It never fires when the component is destroyed )

That might only be possible in an e2e test, but I think that would be too complex.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure we aren't missing anything, you tested this on the browser targets (not the node targets) ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the entire test suite with pnpm test //packages/common/... and also made sure to try it directly with pnpm //packages/common/test:test_web_chromium.

However, I was unable to replicate it.

I manually verified the fix in Chrome.

prevents browsers from re-fetch image during DOM teardown
when using `sizes="auto"` with lazy loading.

Fixes angular#67055
@SkyZeroZx SkyZeroZx force-pushed the fix/img-directive-refetch branch from 0908cac to 6642711 Compare March 17, 2026 15:21
Copy link
Copy Markdown
Member

@JeanMeche JeanMeche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the investigation and the information provided.

@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Mar 19, 2026
@leonsenft leonsenft merged commit c1312da into angular:main Mar 19, 2026
23 checks passed
@leonsenft
Copy link
Copy Markdown
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: common Issues related to APIs in the @angular/common package target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected 100vw image fetch when navigating away from components due to sizes="auto" in Chromium

3 participants