diff --git a/.ado/jobs/cli-init.yml b/.ado/jobs/cli-init.yml index 761a3ee86ef..13a57c0a2f3 100644 --- a/.ado/jobs/cli-init.yml +++ b/.ado/jobs/cli-init.yml @@ -51,32 +51,32 @@ parameters: platform: x86 projectType: lib additionalRunArguments: --no-autolink --no-deploy - - Name: X86DebugCppHermes + - Name: X86DebugCppChakra language: cpp configuration: Debug platform: x86 projectType: app - additionalInitArguments: --useHermes - - Name: X64ReleaseCsHermes + useChakra: true + - Name: X64ReleaseCsChakra language: cs configuration: Release platform: x64 projectType: app - additionalInitArguments: --useHermes + useChakra: true runWack: true - - Name: Arm64ReleaseCsHermes + - Name: Arm64ReleaseCsChakra language: cs configuration: Release platform: ARM64 projectType: app - additionalInitArguments: --useHermes + useChakra: true additionalRunArguments: --no-deploy - - Name: X64ReleaseCppHermes + - Name: X64ReleaseCppChakra language: cpp configuration: Release platform: x64 projectType: app - additionalInitArguments: --useHermes + useChakra: true runWack: true - Name: X86DebugCppNuget language: cpp @@ -224,32 +224,32 @@ parameters: platform: x86 projectType: lib additionalRunArguments: --no-autolink --no-deploy - - Name: X86DebugCppHermes + - Name: X86DebugCppChakra language: cpp configuration: Debug platform: x86 projectType: app - additionalInitArguments: --useHermes - - Name: X64ReleaseCsHermes + useChakra: true + - Name: X64ReleaseCsChakra language: cs configuration: Release platform: x64 projectType: app - additionalInitArguments: --useHermes + useChakra: true runWack: true - - Name: Arm64ReleaseCsHermes + - Name: Arm64ReleaseCsChakra language: cs configuration: Release platform: ARM64 projectType: app - additionalInitArguments: --useHermes + useChakra: true additionalRunArguments: --no-deploy - - Name: X64ReleaseCppHermes + - Name: X64ReleaseCppChakra language: cpp configuration: Release platform: x64 projectType: app - additionalInitArguments: --useHermes + useChakra: true runWack: true - Name: X86DebugCppNuget language: cpp @@ -410,4 +410,5 @@ jobs: additionalRunArguments: ${{ matrix.additionalRunArguments }} runWack: ${{ coalesce(matrix.runWack, false) }} buildEnvironment: ${{ parameters.buildEnvironment }} + useChakra: ${{ coalesce(matrix.useChakra, false) }} useNuGet: ${{ coalesce(matrix.useNuGet, false) }} \ No newline at end of file diff --git a/.ado/jobs/e2e-test.yml b/.ado/jobs/e2e-test.yml index 5169f2f9ba4..ea17be352fc 100644 --- a/.ado/jobs/e2e-test.yml +++ b/.ado/jobs/e2e-test.yml @@ -15,30 +15,30 @@ parameters: Matrix: - Name: X64Chakra BuildPlatform: x64 - UseHermes: false + UseChakra: true - Name: X64Hermes BuildPlatform: x64 - UseHermes: true + UseChakra: false - Name: X86Chakra BuildPlatform: x86 - UseHermes: false + UseChakra: true - Name: X86Hermes BuildPlatform: x86 - UseHermes: true + UseChakra: false - BuildEnvironment: Continuous Matrix: - Name: X64Chakra BuildPlatform: x64 - UseHermes: false + UseChakra: true - Name: X64Hermes BuildPlatform: x64 - UseHermes: true + UseChakra: false - Name: X86Chakra BuildPlatform: x86 - UseHermes: false + UseChakra: true - Name: X86Hermes BuildPlatform: x86 - UseHermes: true + UseChakra: false jobs: - ${{ each config in parameters.buildMatrix }}: @@ -77,7 +77,7 @@ jobs: parameters: package: packages/e2e-test-app feature: UseHermes - value: ${{ matrix.UseHermes }} + value: ${{ not(coalesce(matrix.UseChakra, false)) }} - template: ../templates/run-windows-with-certificates.yml parameters: @@ -157,7 +157,7 @@ jobs: - ${{ each config in parameters.buildMatrix }}: - ${{ if eq(config.BuildEnvironment, parameters.buildEnvironment) }}: - ${{ each matrix in config.Matrix }}: - - ${{ if eq(matrix.UseHermes, true) }}: + - ${{ if eq(matrix.UseChakra, false) }}: - job: E2ETestFabric${{ matrix.Name }} displayName: E2E Test App Fabric ${{ matrix.Name }} diff --git a/.ado/jobs/integration-test.yml b/.ado/jobs/integration-test.yml index 3557b133c33..bee316fa510 100644 --- a/.ado/jobs/integration-test.yml +++ b/.ado/jobs/integration-test.yml @@ -16,54 +16,64 @@ parameters: BuildPlatform: ARM64 BuildConfiguration: Debug DeployOptions: --no-deploy # We don't have Arm agents - UseHermes: false - Name: X64WebDebug BuildPlatform: x64 BuildConfiguration: Debug DeployOptions: - UseHermes: false - - Name: X64ReleaseHermes + - Name: X86WebDebug + BuildPlatform: x86 + BuildConfiguration: Debug + DeployOptions: + - Name: X64Release BuildPlatform: x64 BuildConfiguration: Release DeployOptions: - UseHermes: true - - Name: X86WebDebug + - Name: X86Release BuildPlatform: x86 - BuildConfiguration: Debug + BuildConfiguration: Release + DeployOptions: + - Name: X64ReleaseChakra + BuildPlatform: x64 + BuildConfiguration: Release DeployOptions: - UseHermes: false - - Name: X86ReleaseHermes + UseChakra: true + - Name: X86ReleaseChakra BuildPlatform: x86 BuildConfiguration: Release DeployOptions: - UseHermes: true + UseChakra: true - BuildEnvironment: Continuous Matrix: - Name: Arm64Debug BuildPlatform: ARM64 BuildConfiguration: Debug DeployOptions: --no-deploy # We don't have Arm agents - UseHermes: false - Name: X64WebDebug BuildPlatform: x64 BuildConfiguration: Debug DeployOptions: - UseHermes: false - - Name: X64ReleaseHermes + - Name: X86WebDebug + BuildPlatform: x86 + BuildConfiguration: Debug + DeployOptions: + - Name: X64Release BuildPlatform: x64 BuildConfiguration: Release DeployOptions: - UseHermes: true - - Name: X86WebDebug + - Name: X86Release BuildPlatform: x86 - BuildConfiguration: Debug + BuildConfiguration: Release + DeployOptions: + - Name: X64ReleaseChakra + BuildPlatform: x64 + BuildConfiguration: Release DeployOptions: - UseHermes: false - - Name: X86ReleaseHermes + UseChakra: true + - Name: X86ReleaseChakra BuildPlatform: x86 BuildConfiguration: Release DeployOptions: - UseHermes: true + UseChakra: true jobs: - ${{ each config in parameters.buildMatrix }}: @@ -101,7 +111,7 @@ jobs: parameters: package: packages/integration-test-app feature: UseHermes - value: ${{ matrix.UseHermes }} + value: ${{ not(coalesce(matrix.UseChakra, false))}} - ${{ if eq(matrix.BuildConfiguration, 'Debug') }}: # The build is more likely to crash after we've started other bits that diff --git a/.ado/templates/react-native-init.yml b/.ado/templates/react-native-init.yml index 6c00615b7a9..bd5c78f8d0a 100644 --- a/.ado/templates/react-native-init.yml +++ b/.ado/templates/react-native-init.yml @@ -24,6 +24,9 @@ parameters: - name: additionalRunArguments type: string default: '' + - name: useChakra + type: boolean + default: false - name: useNuGet type: boolean default: false @@ -102,6 +105,12 @@ steps: workingDirectory: $(Agent.BuildDirectory)\testcli env: npm_config_registry: http://localhost:4873 + + - template: set-experimental-feature.yml + parameters: + package: ..\testcli + feature: UseHermes + value: ${{ not(parameters.UseChakra) }} - ${{ if eq(parameters.projectType, 'app') }}: - powershell: | diff --git a/change/@react-native-windows-cli-b478dee5-f5a0-4257-96b1-c3cd1ce241f0.json b/change/@react-native-windows-cli-b478dee5-f5a0-4257-96b1-c3cd1ce241f0.json new file mode 100644 index 00000000000..f344cff870e --- /dev/null +++ b/change/@react-native-windows-cli-b478dee5-f5a0-4257-96b1-c3cd1ce241f0.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "[0.73] Make Hermes the default JS engine", + "packageName": "@react-native-windows/cli", + "email": "jthysell@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/change/react-native-windows-199ec877-3e4a-4205-bdf0-60a698957050.json b/change/react-native-windows-199ec877-3e4a-4205-bdf0-60a698957050.json new file mode 100644 index 00000000000..9873828d8c1 --- /dev/null +++ b/change/react-native-windows-199ec877-3e4a-4205-bdf0-60a698957050.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "[0.73] Make Hermes the default JS engine", + "packageName": "react-native-windows", + "email": "jthysell@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/packages/@react-native-windows/cli/src/commands/config/configUtils.ts b/packages/@react-native-windows/cli/src/commands/config/configUtils.ts index b716eb481b8..3b69b04cd73 100644 --- a/packages/@react-native-windows/cli/src/commands/config/configUtils.ts +++ b/packages/@react-native-windows/cli/src/commands/config/configUtils.ts @@ -300,6 +300,28 @@ export function tryFindPropertyValue( return null; } +/** + * Search for the given property in the project contents and return its value. + * @param projectContents The XML project contents. + * @param propertyName The property to look for. + * @return The value of the tag if it exists. + */ +export function tryFindPropertyValueAsBoolean( + projectContents: Node, + propertyName: string, +): boolean | null { + const rawValue = tryFindPropertyValue(projectContents, propertyName); + + switch (rawValue) { + case 'true': + return true; + case 'false': + return false; + default: + return null; + } +} + export function findPropertyValue( projectContents: Node, propertyName: string, diff --git a/packages/@react-native-windows/cli/src/generator-windows/index.ts b/packages/@react-native-windows/cli/src/generator-windows/index.ts index da80bd67509..8f8214e1b28 100644 --- a/packages/@react-native-windows/cli/src/generator-windows/index.ts +++ b/packages/@react-native-windows/cli/src/generator-windows/index.ts @@ -16,6 +16,7 @@ import findUp from 'find-up'; import { readProjectFile, findPropertyValue, + tryFindPropertyValueAsBoolean, } from '../commands/config/configUtils'; import { @@ -130,6 +131,27 @@ export async function copyProjectTemplateAndReplace( console.log('Using experimental NuGet dependency.'); } + const experimentalPropsPath = path.join( + destPath, + windowsDir, + 'ExperimentalFeatures.props', + ); + + let existingUseHermes: boolean | null = null; + if (fs.existsSync(experimentalPropsPath)) { + existingUseHermes = tryFindPropertyValueAsBoolean( + readProjectFile(experimentalPropsPath), + 'UseHermes', + ); + } + + if (existingUseHermes === false) { + console.warn( + 'Hermes is now the default JS engine and will be enabled for this project. Support for Chakra will be deprecated in the future. To disable Hermes and keep using Chakra for now, see https://microsoft.github.io/react-native-windows/docs/hermes#disabling-hermes.', + ); + } + options.useHermes = true; + if (options.useWinUI3) { throw new CodedError( 'IncompatibleOptions', diff --git a/packages/e2e-test-app/windows/ExperimentalFeatures.props b/packages/e2e-test-app/windows/ExperimentalFeatures.props index 17a7b786d11..062a92feb03 100644 --- a/packages/e2e-test-app/windows/ExperimentalFeatures.props +++ b/packages/e2e-test-app/windows/ExperimentalFeatures.props @@ -2,7 +2,7 @@ - false + true true true diff --git a/packages/integration-test-app/windows/ExperimentalFeatures.props b/packages/integration-test-app/windows/ExperimentalFeatures.props index 17a7b786d11..062a92feb03 100644 --- a/packages/integration-test-app/windows/ExperimentalFeatures.props +++ b/packages/integration-test-app/windows/ExperimentalFeatures.props @@ -2,7 +2,7 @@ - false + true true true diff --git a/vnext/Microsoft.ReactNative.IntegrationTests/JsiSimpleTurboModuleTests.js b/vnext/Microsoft.ReactNative.IntegrationTests/JsiSimpleTurboModuleTests.js index c20035f5797..ce40b9fa1aa 100644 --- a/vnext/Microsoft.ReactNative.IntegrationTests/JsiSimpleTurboModuleTests.js +++ b/vnext/Microsoft.ReactNative.IntegrationTests/JsiSimpleTurboModuleTests.js @@ -6,6 +6,10 @@ * @format */ +// Make sure that we import something from react-native so that we build a complete bundle +// eslint-disable-next-line no-unused-vars +import {View} from 'react-native'; + import {default as myTrivialTurboModule} from './NativeMyTrivialTurboModule'; myTrivialTurboModule.startFromJS(); diff --git a/vnext/Microsoft.ReactNative.IntegrationTests/JsiTurboModuleTests.js b/vnext/Microsoft.ReactNative.IntegrationTests/JsiTurboModuleTests.js index 4163f358cfa..1a9e8552fbb 100644 --- a/vnext/Microsoft.ReactNative.IntegrationTests/JsiTurboModuleTests.js +++ b/vnext/Microsoft.ReactNative.IntegrationTests/JsiTurboModuleTests.js @@ -6,6 +6,10 @@ * @format */ +// Make sure that we import something from react-native so that we build a complete bundle +// eslint-disable-next-line no-unused-vars +import {View} from 'react-native'; + import {default as mySimpleTurboModule} from './NativeMySimpleTurboModuleCxx'; // The logging of the TurboModule functions is verified against the test action sequence. diff --git a/vnext/Microsoft.ReactNative.IntegrationTests/TestBundle.targets b/vnext/Microsoft.ReactNative.IntegrationTests/TestBundle.targets index 78f322af3e4..46af80df295 100644 --- a/vnext/Microsoft.ReactNative.IntegrationTests/TestBundle.targets +++ b/vnext/Microsoft.ReactNative.IntegrationTests/TestBundle.targets @@ -1,12 +1,20 @@ + + $(OutputPath) + $(OutputPath)sourcemaps\react + - - + Outputs=" + @(JsBundleEntry->'$(BundleOutputPath)%(Filename).bundle'); + @(JsBundleEntry->'$(BundleSourceMapDir)\%(Filename).bundle.packager.map')"> + + + + diff --git a/vnext/PropertySheets/External/Microsoft.ReactNative.Composition.Common.props b/vnext/PropertySheets/External/Microsoft.ReactNative.Composition.Common.props index 8f336ad8797..db2f915b039 100644 --- a/vnext/PropertySheets/External/Microsoft.ReactNative.Composition.Common.props +++ b/vnext/PropertySheets/External/Microsoft.ReactNative.Composition.Common.props @@ -8,5 +8,13 @@ Do not make any changes here unless it applies to ALL such projects. --> + + + + + + true + + diff --git a/vnext/PropertySheets/JSEngine.props b/vnext/PropertySheets/JSEngine.props index 0aaae40db78..192bcc2535b 100644 --- a/vnext/PropertySheets/JSEngine.props +++ b/vnext/PropertySheets/JSEngine.props @@ -12,7 +12,7 @@ true - false + true 0.1.15 $(PkgMicrosoft_JavaScript_Hermes) diff --git a/vnext/metro.config.js b/vnext/metro.config.js index 9c8de2a7c70..40c757691b7 100644 --- a/vnext/metro.config.js +++ b/vnext/metro.config.js @@ -19,4 +19,4 @@ if ( } const {makeMetroConfig} = require('@rnw-scripts/metro-dev-config'); -module.exports = makeMetroConfig(); +module.exports = makeMetroConfig({projectRoot: __dirname}); diff --git a/vnext/templates/cpp-app/windows/ExperimentalFeatures.props b/vnext/templates/cpp-app/windows/ExperimentalFeatures.props index a377a7a7528..6b4e69eb6c1 100644 --- a/vnext/templates/cpp-app/windows/ExperimentalFeatures.props +++ b/vnext/templates/cpp-app/windows/ExperimentalFeatures.props @@ -2,7 +2,6 @@ - true true false diff --git a/vnext/templates/old/generateWrapper.js b/vnext/templates/old/generateWrapper.js index 4d9ec1d99c8..8772289f094 100644 --- a/vnext/templates/old/generateWrapper.js +++ b/vnext/templates/old/generateWrapper.js @@ -20,7 +20,7 @@ function makeGenerateWindowsWrapper( })` : `React Native Windows Application (Old Arch, UWP, ${ language === 'cs' ? 'C#' : 'C++' - }, Chakra)`; + }, Hermes)`; const description = projectType === 'lib' ? `A RNW module written in ${ @@ -28,7 +28,7 @@ function makeGenerateWindowsWrapper( }, targeting UWP and RN's old architecture.` : `A RNW app written in ${ language === 'cs' ? 'C#' : 'C++' - }, targeting UWP and RN's old architecture, with the Chakra JS engine.`; + }, targeting UWP and RN's old architecture, with the Hermes JS engine.`; const postInstall = async (config = {}, options = {}) => { const experimentalFeatures = config?.project?.windows?.experimentalFeatures; @@ -40,7 +40,7 @@ function makeGenerateWindowsWrapper( experimentalNuGetDependency: experimentalFeatures?.UseExperimentalNuget ?? false, useWinUI3: experimentalFeatures?.UseWinUI3 ?? false, - useHermes: experimentalFeatures?.UseHermes ?? false, + useHermes: experimentalFeatures?.UseHermes ?? true, useDevMode: false, verbose: !!options.logging, telemetry: !!options.telemetry, diff --git a/vnext/templates/old/uwp-cpp-lib/template.config.js b/vnext/templates/old/uwp-cpp-lib/template.config.js index 12c21263199..434214ba44b 100644 --- a/vnext/templates/old/uwp-cpp-lib/template.config.js +++ b/vnext/templates/old/uwp-cpp-lib/template.config.js @@ -12,4 +12,4 @@ const {makeGenerateWindowsWrapper} = require('../generateWrapper'); -module.exports = makeGenerateWindowsWrapper('cpp', 'lib', false); +module.exports = makeGenerateWindowsWrapper('cpp', 'lib');