Skip to content

fix(Image): support data: URIs in getSize/getSizeWithHeaders on Android - #57808

Open
stareezy-1 wants to merge 2 commits into
react:mainfrom
stareezy-1:fix/image-getsize-data-uri
Open

fix(Image): support data: URIs in getSize/getSizeWithHeaders on Android#57808
stareezy-1 wants to merge 2 commits into
react:mainfrom
stareezy-1:fix/image-getsize-data-uri

Conversation

@stareezy-1

Copy link
Copy Markdown

Summary

Fixes Image.getSize() and Image.getSizeWithHeaders() failing with IllegalArgumentException when called with data: URIs on Android (regression since 0.86).

Fixes #57787

Changelog:

[ANDROID] [FIXED] - Image.getSize/getSizeWithHeaders now works with data: URIs

Problem

#56736 changed getSize() from fetchDecodedImage() to fetchEncodedImage() to fix downsampled dimension reporting for large images. However, Fresco's encoded-image producer sequence doesn't support the data URI scheme, throwing:

IllegalArgumentException: Unsupported uri scheme for encoded image fetch!
Uri is: data:image/jpeg;base64,/9j/4AA...

Displaying data: URIs via <Image source={{ uri }}/> still works because rendering uses the decoded-image pipeline.

Solution

Added a fast path (matching the pattern from #56944's res:// fix) that detects data: URIs and routes them through fetchDecodedImage(), which supports data URIs via DataFetchProducer:

if ("data" == source.uri.scheme) {
  resolveDecodedImageSize(source, promise)
  return
}

Applied to both getSize() and getSizeWithHeaders().

Test Plan

Since Hermes is the only supported JS engine and always provides a native
Promise implementation, the `else` branch in polyfillPromise.js that
imports the `promise` package via `../Promise` is dead code that can
never execute (`hasPromise()` is always true).

This dead import causes the bundler to include the entire `promise`
package (~15KB) in every app's JS bundle despite it never being used.

Remove the dead branch and the unused `polyfillGlobal` import.

Fixes react#57702
After react#56736 changed getSize() from fetchDecodedImage to
fetchEncodedImage, data: URIs started throwing
IllegalArgumentException because Fresco's encoded-image producer
sequence does not support the 'data' URI scheme.

Add a fast path (similar to the res:// fast path from react#56944) that
routes data: URIs through fetchDecodedImage, which supports data: URIs
via DataFetchProducer.

This restores the behavior from 0.84.x where Image.getSize() worked
correctly with base64-encoded data: URIs.

Fixes react#57787
@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 Aug 4, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 4, 2026
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. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【Android】【0.86.2】Image.getSize() fails for data: URIs on Android since v0.86

1 participant