Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React 74.5: loading images from data: URIs fails on iOS 15, works on 18 #48494

Open
reijin90 opened this issue Jan 4, 2025 · 2 comments
Open
Labels
Component: Image Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Newer Patch Available Platform: iOS iOS applications.

Comments

@reijin90
Copy link

reijin90 commented Jan 4, 2025

Description

I think this is related to: #42234
I tried reproducing it in the Expo Stack, but was not able to do it with the example on the website (https://reactnative.dev/docs/image#src). I can only presume this is because this happens in a native component.
Here is my code that is as close as possible to the error:

            console.log(`image: ${image.substring(0, 50)}...`),
            <TouchableOpacity key={imgIndex} onPress={() => { setSelectedImage(image); setSelectedFileName(fileName); }}>
              <Image source={{ uri: image }} style={globalStyles.imageThumbnail} onError={(error) => console.error(`${error} image: ${image.substring(image.length-50, image.length)}`)} />
            </TouchableOpacity>

Basically what causes the problem is that on iOS 15 (iphone 6s) the data uri that is being loaded by the Image component receives a .png at the end and a file:// at the beginning. As seen here (this is the warning that is presented to me, I think it comes from the component)
image
And this is the console output (note the warning text with the base64 encoded image data ending with .png, whereas the uri parameter given to the Image component does not have it):

rarKc0szkF5Bp5VemorXUBIcBJkhGhB2NwDc7/teeZ7DaCF52NMLw9Ks9AsOHPx%0D%0A58aFAJoJFGcCqwY+56o4C88CtPBMtlNg9TerPI95m2m20gM0IA08V+W5qc9A9ByA%0D%0A9n3gcQCY90iFZ33TVbWu4Ox4Hjyzv77O2PjrBNDCGUpyVZpVn8312JjqXPfdzQBd%0D%0A4RlVl23sHCrQLCgkKG9XFxRuH8raNYiO/xl4FqBRobnht6wdn6l5EM3fzr+l/5s+%0D%0AL4Jnji0D6P8HoPs5K+6F5G8AAAAASUVORK5CYII=.png
 ERROR  [object Object] image: zr+l/5s+
L4Jnji0D6P8HoPs5K+6F5G8AAAAASUVORK5CYII=

On iOS 18 this behavior (adding png and file) does not get triggered.

Edit:
I did some digging, and the function that shows the Could not find image warning from the screenshot, which already contains the malformed URI, does not even get triggered on the newer iOS version. To test this, I adjusted the code for both locations where the error is triggered:

- (nullable RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
                                                       size:(CGSize)size
                                                      scale:(CGFloat)scale
                                                 resizeMode:(RCTResizeMode)resizeMode
                                            progressHandler:(RCTImageLoaderProgressBlock)progressHandler
                                         partialLoadHandler:(RCTImageLoaderPartialLoadBlock)partialLoadHandler
                                          completionHandler:(RCTImageLoaderCompletionBlock)completionHandler
{
  UIImage *image = RCTImageFromLocalAssetURL(imageURL);
  NSString *message = [NSString stringWithFormat:@"CHANGED2_LOGCould not find image %@", imageURL];
  RCTLogWarn(@"%@", message);
  if (image) {
    if (progressHandler) {
      progressHandler(1, 1);
    }
    completionHandler(nil, image);
  } else {
    NSString *message = [NSString stringWithFormat:@"CHANGED2Could not find image %@", imageURL];
    RCTLogWarn(@"%@", message);
    completionHandler(RCTErrorWithMessage(message), nil);
  }

  return nil;
}

and

- (nullable RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
                                                       size:(CGSize)size
                                                      scale:(CGFloat)scale
                                                 resizeMode:(RCTResizeMode)resizeMode
                                            progressHandler:(RCTImageLoaderProgressBlock)progressHandler
                                         partialLoadHandler:(RCTImageLoaderPartialLoadBlock)partialLoadHandler
                                          completionHandler:(RCTImageLoaderCompletionBlock)completionHandler
{
  UIImage *image = RCTImageFromLocalAssetURL(imageURL);
  NSString *message = [NSString stringWithFormat:@"CHANGED_LOGCould not find image %@", imageURL];
  RCTLogWarn(@"%@", message);
  if (image) {
    if (progressHandler) {
      progressHandler(1, 1);
    }
    completionHandler(nil, image);
  } else {
    NSString *message = [NSString stringWithFormat:@"CHANGEDCould not find image %@", imageURL];
    RCTLogWarn(@"%@", message);
    completionHandler(RCTErrorWithMessage(message), nil);
  }

  return nil;
}

For reference, loadImageForURL is the one getting triggered on iOS 15, and no logs are generated on iOS 18.

Steps to reproduce

hand over data uri with base64 encoded image in <Image source={{ uri: image }}

React Native Version

0.74.5

Affected Platforms

Runtime - iOS

Output of npx react-native info

System:
  OS: macOS 15.1.1
  CPU: (14) arm64 Apple M4 Pro
  Memory: 202.11 MB / 48.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 23.3.0
    path: /opt/homebrew/bin/node
  Yarn: Not Found
  npm:
    version: 10.9.0
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2024.12.02.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK:
    API Levels:
      - "25"
      - "33"
      - "34"
    Build Tools:
      - 34.0.0
      - 35.0.0
    System Images:
      - android-24 | ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23339.11.2421.12550806
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.5
    wanted: 0.74.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Stacktrace or Logs

see in main message, but here:

rarKc0szkF5Bp5VemorXUBIcBJkhGhB2NwDc7/teeZ7DaCF52NMLw9Ks9AsOHPx%0D%0A58aFAJoJFGcCqwY+56o4C88CtPBMtlNg9TerPI95m2m20gM0IA08V+W5qc9A9ByA%0D%0A9n3gcQCY90iFZ33TVbWu4Ox4Hjyzv77O2PjrBNDCGUpyVZpVn8312JjqXPfdzQBd%0D%0A4RlVl23sHCrQLCgkKG9XFxRuH8raNYiO/xl4FqBRobnht6wdn6l5EM3fzr+l/5s+%0D%0AL4Jnji0D6P8HoPs5K+6F5G8AAAAASUVORK5CYII=.png
 ERROR  [object Object] image: zr+l/5s+
L4Jnji0D6P8HoPs5K+6F5G8AAAAASUVORK5CYII=


### Reproducer

https://snack.expo.dev/@btr/image-example

### Screenshots and Videos

_No response_
@react-native-bot
Copy link
Collaborator

Tip

Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - 0.74.6. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot
Copy link
Collaborator

Tip

Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@cortinico cortinico added Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. and removed Needs: Triage 🔍 labels Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Image Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. Newer Patch Available Platform: iOS iOS applications.
Projects
None yet
Development

No branches or pull requests

3 participants