Skip to content

Commit 4d7c4bd

Browse files
jakex7facebook-github-bot
authored andcommitted
Fix ImageSource require (#50963)
Summary: In react-native-svg, I found that the `Image` component stopped working starting with `react-native@0.79`. After some debugging, I traced the issue to the migration of `Libraries/Image` to the new export syntax (see 8783196). To fix this, I updated the import to match other requires, similar to https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js#L84. ## Changelog: [GENERAL] [FIXED] - Fix codegen ImageSource require Pull Request resolved: #50963 Test Plan: `validAttributes` process should be a function instead of object with a default property. Before: <img width="1041" alt="image" src="https://github.com/user-attachments/assets/9fbc9e9f-6c45-4b0b-adb8-2eb911676fe1" /> After: <img width="1005" alt="image" src="https://github.com/user-attachments/assets/ee594103-90da-4917-8252-72f4ecfc28e1" /> Reviewed By: Abbondanzo Differential Revision: D73778127 Pulled By: huntie fbshipit-source-id: ae80c770e8e578794ae1356751f170ff955e1f5a
1 parent 6ea24f7 commit 4d7c4bd

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ export const __INTERNAL_VIEW_CONFIG = {
367367
uiViewClassName: \\"ImagePropNativeComponentView\\",
368368
validAttributes: {
369369
thumbImage: {
370-
process: require('react-native/Libraries/Image/resolveAssetSource')
370+
process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource'))
371371
}
372372
}
373373
};
@@ -503,7 +503,7 @@ export const __INTERNAL_VIEW_CONFIG = {
503503
uiViewClassName: \\"MultiNativePropNativeComponentView\\",
504504
validAttributes: {
505505
thumbImage: {
506-
process: require('react-native/Libraries/Image/resolveAssetSource')
506+
process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource'))
507507
},
508508
color: {
509509
process: require('react-native/Libraries/StyleSheet/processColor').default

packages/react-native-codegen/e2e/namespaced/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ export const __INTERNAL_VIEW_CONFIG = {
367367
uiViewClassName: \\"ImagePropNativeComponentView\\",
368368
validAttributes: {
369369
thumbImage: {
370-
process: require('react-native/Libraries/Image/resolveAssetSource')
370+
process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource'))
371371
}
372372
}
373373
};
@@ -503,7 +503,7 @@ export const __INTERNAL_VIEW_CONFIG = {
503503
uiViewClassName: \\"MultiNativePropNativeComponentView\\",
504504
validAttributes: {
505505
thumbImage: {
506-
process: require('react-native/Libraries/Image/resolveAssetSource')
506+
process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource'))
507507
},
508508
color: {
509509
process: require('react-native/Libraries/StyleSheet/processColor').default

packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function getReactDiffProcessValue(typeAnnotation: PropTypeAnnotation) {
7575
);
7676
case 'ImageSourcePrimitive':
7777
return expression(
78-
"{ process: require('react-native/Libraries/Image/resolveAssetSource') }",
78+
"{ process: ((req) => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource')) }",
7979
);
8080
case 'ImageRequestPrimitive':
8181
throw new Error('ImageRequest should not be used in props');

packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ export const __INTERNAL_VIEW_CONFIG = {
590590
uiViewClassName: \\"ImagePropNativeComponent\\",
591591
validAttributes: {
592592
thumbImage: {
593-
process: require('react-native/Libraries/Image/resolveAssetSource')
593+
process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource'))
594594
}
595595
}
596596
};
@@ -788,7 +788,7 @@ export const __INTERNAL_VIEW_CONFIG = {
788788
uiViewClassName: \\"ImageColorPropNativeComponent\\",
789789
validAttributes: {
790790
thumbImage: {
791-
process: require('react-native/Libraries/Image/resolveAssetSource')
791+
process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource'))
792792
},
793793
color: {
794794
process: require('react-native/Libraries/StyleSheet/processColor').default

0 commit comments

Comments
 (0)