Skip to content

Conversation

@Abbondanzo
Copy link
Contributor

Summary:

Issue

When prefetching images with the resizeMethod prop set, there's a brief period of time where the image has not laid out and the dimensions are 0x0. Since ImageSource.h only considers the type and uri properties for equality, two different ImageSource objects would be considered equal despite having different size. We would continue on to prefetch the image in its fullest quality and retain that image in ImageState, bailing out early in the ImageShadowNode::updateStateIfNeeded method since both the old image source and image request params are equal in this case.

Fix

Rather than adding size to the equality check, this change adds identical logic directly from ReactImageView to determine if we should postpone the image request: if the image is resizable and we don't have a width or a height, postpone!

Additional Context

I noodled with a few spots of where this should ultimately live, but this seemed like the least invasive without making some larger refactors. The other approach I considered was to instead return an optional ImageRequest object from ImageManager->requestImage call to signal that no request was ever made, and using the ImageRequest response as part of the equality check.

Changelog: [Internal]

Differential Revision: D85200818

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 22, 2025
@meta-codesync
Copy link

meta-codesync bot commented Oct 22, 2025

@Abbondanzo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D85200818.

Abbondanzo added a commit to Abbondanzo/react-native that referenced this pull request Oct 22, 2025
Summary:

## Issue
When prefetching images with the `resizeMethod` prop set, there's a brief period of time where the image has not laid out and the dimensions are 0x0. Since `ImageSource.h` only considers the `type` and `uri` properties for equality, two different `ImageSource` objects would be considered equal despite having different `size`. We would continue on to prefetch the image in its fullest quality and retain that image in `ImageState`, and upon subsequent requests once we have non-zero layouts, we would bail out early in the `ImageShadowNode::updateStateIfNeeded` method since both the old image source and image request params are equal in this case.

## Fix
Rather than adding `size` to the equality check, this change adds identical logic directly from `ReactImageView` to determine if we should postpone the image request: if the image is resizable and we don't have a width or a height, postpone!

## Additional Context
I noodled with a few spots of where this should ultimately live, but this seemed like the least invasive without making some larger refactors. The other approach I considered was to instead return an optional `ImageRequest` object from `ImageManager->requestImage call` to signal that no request was ever made, and using the `ImageRequest` response as part of the equality check.


Changelog: [Internal]

Differential Revision: D85200818
Abbondanzo added a commit to Abbondanzo/react-native that referenced this pull request Oct 22, 2025
Summary:

## Issue
When prefetching images with the `resizeMethod` prop set, there's a brief period of time where the image has not laid out and the dimensions are 0x0. Since `ImageSource.h` only considers the `type` and `uri` properties for equality, two different `ImageSource` objects would be considered equal despite having different `size`. We would continue on to prefetch the image in its fullest quality and retain that image in `ImageState`, and upon subsequent requests once we have non-zero layouts, we would bail out early in the `ImageShadowNode::updateStateIfNeeded` method since both the old image source and image request params are equal in this case.

## Fix
Rather than adding `size` to the equality check, this change adds identical logic directly from `ReactImageView` to determine if we should postpone the image request: if the image is resizable and we don't have a width or a height, postpone!

## Additional Context
I noodled with a few spots of where this should ultimately live, but this seemed like the least invasive without making some larger refactors. The other approach I considered was to instead return an optional `ImageRequest` object from `ImageManager->requestImage call` to signal that no request was ever made, and using the `ImageRequest` response as part of the equality check.


Changelog: [Internal]

Differential Revision: D85200818
Summary:
Pull Request resolved: facebook#54228

## Issue
When prefetching images with the `resizeMethod` prop set, there's a brief period of time where the image has not laid out and the dimensions are 0x0. Since `ImageSource.h` only considers the `type` and `uri` properties for equality, two different `ImageSource` objects would be considered equal despite having different `size`. We would continue on to prefetch the image in its fullest quality and retain that image in `ImageState`, and upon subsequent requests once we have non-zero layouts, we would bail out early in the `ImageShadowNode::updateStateIfNeeded` method since both the old image source and image request params are equal in this case.

## Fix
Rather than adding `size` to the equality check, this change adds identical logic directly from `ReactImageView` to determine if we should postpone the image request: if the image is resizable and we don't have a width or a height, postpone!

## Additional Context
I noodled with a few spots of where this should ultimately live, but this seemed like the least invasive without making some larger refactors. The other approach I considered was to instead return an optional `ImageRequest` object from `ImageManager->requestImage call` to signal that no request was ever made, and using the `ImageRequest` response as part of the equality check.

Changelog: [Internal]

Reviewed By: christophpurrer

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants