From b20bcf9b021cebc70edde96c18e6b362ef390606 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 11 Sep 2025 05:01:41 -0700 Subject: [PATCH] Do not invoke project. inside BundleHermesCTask (#53718) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53718 I've just realized we ended up invoking `project.` inside the execution of `BundleHermesCTask`. This is an anti-pattern and is breaking Gradle Configuration caching. Instead we should be checking if hermesV1Enabled is set during the Task registration and pass over this information to the task. Changelog: [Internal] [Changed] - Reviewed By: j-piasecki Differential Revision: D82130643 --- .../main/kotlin/com/facebook/react/TaskConfiguration.kt | 3 +++ .../kotlin/com/facebook/react/tasks/BundleHermesCTask.kt | 8 +++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt index 9984aa67ae8a..47e4646f908c 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt @@ -14,6 +14,7 @@ import com.facebook.react.utils.KotlinStdlibCompatUtils.capitalizeCompat import com.facebook.react.utils.NdkConfiguratorUtils.configureJsEnginePackagingOptions import com.facebook.react.utils.NdkConfiguratorUtils.configureNewArchPackagingOptions import com.facebook.react.utils.ProjectUtils.isHermesEnabled +import com.facebook.react.utils.ProjectUtils.isHermesV1Enabled import com.facebook.react.utils.ProjectUtils.useThirdPartyJSC import com.facebook.react.utils.detectedCliFile import com.facebook.react.utils.detectedEntryFile @@ -48,6 +49,7 @@ internal fun Project.configureReactTasks(variant: Variant, config: ReactExtensio } else { isHermesEnabledInProject } + val isHermesV1Enabled = project.isHermesV1Enabled || rootProject.isHermesV1Enabled val isDebuggableVariant = config.debuggableVariants.get().any { it.equals(variant.name, ignoreCase = true) } val useThirdPartyJSC = project.useThirdPartyJSC @@ -78,6 +80,7 @@ internal fun Project.configureReactTasks(variant: Variant, config: ReactExtensio task.jsBundleDir.set(jsBundleDir) task.resourcesDir.set(resourcesDir) task.hermesEnabled.set(isHermesEnabledInThisVariant) + task.hermesV1Enabled.set(isHermesV1Enabled) task.minifyEnabled.set(!isHermesEnabledInThisVariant) task.devEnabled.set(false) task.jsIntermediateSourceMapsDir.set(jsIntermediateSourceMapsDir) diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt index 6cdd4b5986bb..52ec17479639 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt @@ -63,6 +63,8 @@ abstract class BundleHermesCTask : DefaultTask() { @get:Input abstract val hermesEnabled: Property + @get:Input abstract val hermesV1Enabled: Property + @get:Input abstract val devEnabled: Property @get:Input abstract val extraPackagerArgs: ListProperty @@ -94,12 +96,8 @@ abstract class BundleHermesCTask : DefaultTask() { runCommand(bundleCommand) if (hermesEnabled.get()) { - val hermesV1Enabled = - if (project.rootProject.hasProperty("hermesV1Enabled")) - project.rootProject.findProperty("hermesV1Enabled") == "true" - else false val detectedHermesCommand = - detectOSAwareHermesCommand(root.get().asFile, hermesCommand.get(), hermesV1Enabled) + detectOSAwareHermesCommand(root.get().asFile, hermesCommand.get(), hermesV1Enabled.get()) val bytecodeFile = File("${bundleFile}.hbc") val outputSourceMap = resolveOutputSourceMap(bundleAssetFilename) val compilerSourceMap = resolveCompilerSourceMap(bundleAssetFilename)