Skip to content

Conversation

@fbp93
Copy link

@fbp93 fbp93 commented Mar 7, 2025

Summary:
Fixes #49075

The Image defaultSource prop is causing a runtime error from 0.77 just by using it in the Image component (see error in the linked issue). This might be a regression from some changes in the prop processing logic from either #47710, #47713 or #47754.

Changelog:

[ANDROID] [FIXED] - Fix Image defaultSource runtime error

Pull Request resolved: #49097

Test Plan:

  • Verify it doesn't throw any error on runtime anymore for Android.
  • iOS behaviour should not be impacted as changes are Android specific

In the RNTester, you can use the following component:

import * as React from 'react';
import {Image, View} from 'react-native';

function Playground() {
  return (
    <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
      <Image
        defaultSource={require('../../assets/bandaged.png')}
        source={{
          uri: 'https://i.natgeofe.com/n/548467d8-c5f1-4551-9f58-6817a8d2c45e/NationalGeographic_2572187_4x3.jpg',
        }}
        style={{width: 200, height: 200}}
      />
    </View>
  );
}

Also, this defaultSource prop is ignored in debug builds for Android (as per the docs) – but I've verified we get the defaultSource as a string, which is what we expect on the native side:

Screenshot of the Android logs

image

Reviewed By: javache

Differential Revision: D69052723

Pulled By: cortinico

fbshipit-source-id: 2860dd4c18cefcfcbc4e39f94dfa6305f45773a3

Conflicts:

packages/react-native/Libraries/Image/ImageViewNativeComponent.js

Summary:

Changelog:

Test Plan:

Summary:
Fixes facebook#49075

The Image `defaultSource` prop is causing a runtime error from 0.77 just by using it in the Image component (see error in the linked issue). This might be a regression from some changes in the prop processing logic from either facebook#47710, facebook#47713 or facebook#47754.

## Changelog:

[ANDROID] [FIXED] - Fix Image defaultSource runtime error

Pull Request resolved: facebook#49097

Test Plan:
- Verify it doesn't throw any error on runtime anymore for Android.
- iOS behaviour should not be impacted as changes are Android specific

In the RNTester, you can use the following component:

```tsx
import * as React from 'react';
import {Image, View} from 'react-native';

function Playground() {
  return (
    <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
      <Image
        defaultSource={require('../../assets/bandaged.png')}
        source={{
          uri: 'https://i.natgeofe.com/n/548467d8-c5f1-4551-9f58-6817a8d2c45e/NationalGeographic_2572187_4x3.jpg',
        }}
        style={{width: 200, height: 200}}
      />
    </View>
  );
}
```

Also, this `defaultSource` prop is ignored in debug builds for Android ([as per the docs](https://reactnative.dev/docs/image#defaultsource)) – but I've verified we get the defaultSource as a string, which is what we expect on the native side:

<details>
<summary>Screenshot of the Android logs</summary>

![image](https://github.com/user-attachments/assets/e62ae2c3-6a93-4e44-a2d7-c913f5db2173)

</details>

Reviewed By: javache

Differential Revision: D69052723

Pulled By: cortinico

fbshipit-source-id: 2860dd4c18cefcfcbc4e39f94dfa6305f45773a3

# Conflicts:
#	packages/react-native/Libraries/Image/ImageViewNativeComponent.js
@facebook-github-bot
Copy link
Contributor

Hi @fbp93!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@cortinico
Copy link
Contributor

@fbp93 can you also sign the CLA here: https://code.facebook.com/cla ?

@fbp93
Copy link
Author

fbp93 commented Mar 7, 2025

@fbp93 can you also sign the CLA here: https://code.facebook.com/cla ?

I signed the individual one, is it enough? The company one was asking for contact points etc that I don't have

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-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 Mar 7, 2025
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@cortinico cortinico changed the title Fix Android Image defaultSource runtime error (#49097) [0.77] Fix Android Image defaultSource runtime error (#49097) Mar 7, 2025
@cortinico cortinico merged commit 7c50b5e into facebook:0.77-stable Mar 10, 2025
59 checks passed
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. Pick Request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants