fix(Image): support data: URIs in getSize/getSizeWithHeaders on Android - #57808
Open
stareezy-1 wants to merge 2 commits into
Open
fix(Image): support data: URIs in getSize/getSizeWithHeaders on Android#57808stareezy-1 wants to merge 2 commits into
stareezy-1 wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
Image.getSize()andImage.getSizeWithHeaders()failing withIllegalArgumentExceptionwhen called withdata:URIs on Android (regression since 0.86).Fixes #57787
Changelog:
[ANDROID] [FIXED] - Image.getSize/getSizeWithHeaders now works with data: URIs
Problem
#56736 changed
getSize()fromfetchDecodedImage()tofetchEncodedImage()to fix downsampled dimension reporting for large images. However, Fresco's encoded-image producer sequence doesn't support thedataURI scheme, throwing: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 detectsdata:URIs and routes them throughfetchDecodedImage(), which supports data URIs viaDataFetchProducer:Applied to both
getSize()andgetSizeWithHeaders().Test Plan
Image.getSize('data:image/png;base64,...', cb)now resolves with correct dimensions on AndroidImage.getSizeWithHeaders('data:image/jpeg;base64,...', {}, cb)works correctlygetSize()still usesfetchEncodedImage(preserving Fix Image.getSize returning downsampled dimensions on Android #56736 fix)getSize()still usesresolveResourceSize(preserving Support resource drawable URIs inImage.getSize()on Android (#56944) #56944 fix)