From 807500a63ec496ee8c9e5558c5b6ba6432e60cee Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Thu, 24 Oct 2024 09:36:07 -0700 Subject: [PATCH] Exclude generation of app-defined components from RCTThirdPartyFabricComponentsProvider (#47176) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47176 While writing the guide for the New Architecture, we realized that we need to exclude the generation of the Cls function in the RCTThirdPartyFabricComponentsProvider for components defined in the app. This is needed because a component that is defined in the app will have those function defined in the app project. However, the RCTThirdPartyFabricComponentsProvider is generated in Fabric, inside the Pods project. The pod project needs to build in isolation from the app and cocoapods then link the app to the pods project. But the compilation of the pods project fails if one of the symbol needed by the pods lives in the app. By disabling the generation of that function in th RCTThirdPartyFabricComponentsProvider, we can successfully build the app. The downside is that the user needs to register the component manually, but this is not an issue because if they are writing a component in the app space, they have all the information tomanually register it in the AppDelegate ## Changelog [iOS][Fixed] - Do not generate the ComponentCls function in the RCTThirdPartyFabricComponentsProvider for components deined in the app. Reviewed By: cortinico, blakef Differential Revision: D64739896 fbshipit-source-id: 0eca818ea0198532a611377d14a3ff4c95cb5fe3 --- .../codegen/generate-artifacts-executor.js | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor.js b/packages/react-native/scripts/codegen/generate-artifacts-executor.js index 50717a825e1ab5..bb47205ae4ac2a 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor.js @@ -489,11 +489,22 @@ function rootCodegenTargetNeedsThirdPartyComponentProvider(pkgJson, platform) { return !pkgJsonIncludesGeneratedCode(pkgJson) && platform === 'ios'; } -function dependencyNeedsThirdPartyComponentProvider(schemaInfo, platform) { +function dependencyNeedsThirdPartyComponentProvider( + schemaInfo, + platform, + appCondegenConfigSpec, +) { // Filter the react native core library out. // In the future, core library and third party library should // use the same way to generate/register the fabric components. - return !isReactNativeCoreLibrary(schemaInfo.library.config.name, platform); + // We also have to filter out the the components defined in the app + // because the RCTThirdPartyComponentProvider is generated inside Fabric, + // which lives in a different target from the app and it has no visibility over + // the symbols defined in the app. + return ( + !isReactNativeCoreLibrary(schemaInfo.library.config.name, platform) && + schemaInfo.library.config.name !== appCondegenConfigSpec + ); } function mustGenerateNativeCode(includeLibraryPath, schemaInfo) { @@ -704,8 +715,12 @@ function execute(projectRoot, targetPlatform, baseOutputPath) { if ( rootCodegenTargetNeedsThirdPartyComponentProvider(pkgJson, platform) ) { - const filteredSchemas = schemaInfos.filter( - dependencyNeedsThirdPartyComponentProvider, + const filteredSchemas = schemaInfos.filter(schemaInfo => + dependencyNeedsThirdPartyComponentProvider( + schemaInfo, + platform, + pkgJson.codegenConfig?.appCondegenConfigSpec, + ), ); const schemas = filteredSchemas.map(schemaInfo => schemaInfo.schema); const supportedApplePlatforms = filteredSchemas.map(