Skip to content

Commit fd68f05

Browse files
authored
Make Hermes the default JS engine (#12321)
## Description This PR makes Hermes the default JS engine for RNW going forward. For now, this is still managed by setting the `<UseHermes>` MSBuild property. However, if the property is not explicitly set, the default value in `JSEngine.props` will now be `true` instead of `false`. The property will remain exposed (and now set to `true`) in project's `ExperimentalFeatures.props` files. This will be done for new projects created with the `npx react-native-windows-init` command targeting versions with this change. (Use or omission of the `--useHermes` flag will no longer be recognized at project creation time). Hermes will also be the default for projects created with the new `npx react-native init-windows` CLI command. Current users attempting to *upgrade* their existing projects with these tools will be given a warning if they were previously using the Chakra engine, and instructions to revert back to using Chakra if necessary. However, support for Chakra will be deprecated in the future, so best to migrate sooner rather than later. In addition, this PR should also enable Hermes use when consuming the official (experimental) NuGet package binaries. Finally, this PR updates our CI infrastructure to instead denote "Chakra" (rather than "Hermes") for builds and tests. ### Type of Change - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - This change requires a documentation update ### Why Hermes is the officially supported and maintained JS engine for React Native, and as time goes on, the cost of maintain Chakra (which hasn't been updated in years) only increases. The "new" architecture includes Hermes. Resolves #11251 ### What See above ## Screenshots N/A ## Testing Ran existing tests ## Changelog Should this change be included in the release notes: yes Hermes is now the default JS engine for all new projects and will eventually be the only supported JS engine.
1 parent bb8e04f commit fd68f05

File tree

19 files changed

+143
-48
lines changed

19 files changed

+143
-48
lines changed

.ado/jobs/cli-init.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,32 @@ parameters:
5151
platform: x86
5252
projectType: lib
5353
additionalRunArguments: --no-autolink --no-deploy
54-
- Name: X86DebugCppHermes
54+
- Name: X86DebugCppChakra
5555
language: cpp
5656
configuration: Debug
5757
platform: x86
5858
projectType: app
59-
additionalInitArguments: --useHermes
60-
- Name: X64ReleaseCsHermes
59+
useChakra: true
60+
- Name: X64ReleaseCsChakra
6161
language: cs
6262
configuration: Release
6363
platform: x64
6464
projectType: app
65-
additionalInitArguments: --useHermes
65+
useChakra: true
6666
runWack: true
67-
- Name: Arm64ReleaseCsHermes
67+
- Name: Arm64ReleaseCsChakra
6868
language: cs
6969
configuration: Release
7070
platform: ARM64
7171
projectType: app
72-
additionalInitArguments: --useHermes
72+
useChakra: true
7373
additionalRunArguments: --no-deploy
74-
- Name: X64ReleaseCppHermes
74+
- Name: X64ReleaseCppChakra
7575
language: cpp
7676
configuration: Release
7777
platform: x64
7878
projectType: app
79-
additionalInitArguments: --useHermes
79+
useChakra: true
8080
runWack: true
8181
- Name: X64DebugCppNuget
8282
language: cpp
@@ -134,32 +134,32 @@ parameters:
134134
platform: x86
135135
projectType: lib
136136
additionalRunArguments: --no-autolink --no-deploy
137-
- Name: X86DebugCppHermes
137+
- Name: X86DebugCppChakra
138138
language: cpp
139139
configuration: Debug
140140
platform: x86
141141
projectType: app
142-
additionalInitArguments: --useHermes
143-
- Name: X64ReleaseCsHermes
142+
useChakra: true
143+
- Name: X64ReleaseCsChakra
144144
language: cs
145145
configuration: Release
146146
platform: x64
147147
projectType: app
148-
additionalInitArguments: --useHermes
148+
useChakra: true
149149
runWack: true
150-
- Name: Arm64ReleaseCsHermes
150+
- Name: Arm64ReleaseCsChakra
151151
language: cs
152152
configuration: Release
153153
platform: ARM64
154154
projectType: app
155-
additionalInitArguments: --useHermes
155+
useChakra: true
156156
additionalRunArguments: --no-deploy
157-
- Name: X64ReleaseCppHermes
157+
- Name: X64ReleaseCppChakra
158158
language: cpp
159159
configuration: Release
160160
platform: x64
161161
projectType: app
162-
additionalInitArguments: --useHermes
162+
useChakra: true
163163
runWack: true
164164
- Name: X86DebugCppNuget
165165
language: cpp
@@ -320,4 +320,5 @@ jobs:
320320
additionalRunArguments: ${{ matrix.additionalRunArguments }}
321321
runWack: ${{ coalesce(matrix.runWack, false) }}
322322
buildEnvironment: ${{ parameters.buildEnvironment }}
323+
useChakra: ${{ coalesce(matrix.useChakra, false) }}
323324
useNuGet: ${{ coalesce(matrix.useNuGet, false) }}

.ado/jobs/e2e-test.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@ parameters:
1515
Matrix:
1616
- Name: X64Chakra
1717
BuildPlatform: x64
18-
UseHermes: false
18+
UseChakra: true
1919
- Name: X64Hermes
2020
BuildPlatform: x64
21-
UseHermes: true
21+
UseChakra: false
2222
- BuildEnvironment: Continuous
2323
Matrix:
2424
- Name: X64Chakra
2525
BuildPlatform: x64
26-
UseHermes: false
26+
UseChakra: true
2727
- Name: X64Hermes
2828
BuildPlatform: x64
29-
UseHermes: true
29+
UseChakra: false
3030
- Name: X86Chakra
3131
BuildPlatform: x86
32-
UseHermes: false
32+
UseChakra: true
3333
- Name: X86Hermes
3434
BuildPlatform: x86
35-
UseHermes: true
35+
UseChakra: false
3636

3737
jobs:
3838
- ${{ each config in parameters.buildMatrix }}:
@@ -71,7 +71,7 @@ jobs:
7171
parameters:
7272
package: packages/e2e-test-app
7373
feature: UseHermes
74-
value: ${{ matrix.UseHermes }}
74+
value: ${{ not(coalesce(matrix.UseChakra, false)) }}
7575

7676
- template: ../templates/run-windows-with-certificates.yml
7777
parameters:
@@ -151,7 +151,7 @@ jobs:
151151
- ${{ each config in parameters.buildMatrix }}:
152152
- ${{ if eq(config.BuildEnvironment, parameters.buildEnvironment) }}:
153153
- ${{ each matrix in config.Matrix }}:
154-
- ${{ if eq(matrix.UseHermes, true) }}:
154+
- ${{ if eq(matrix.UseChakra, false) }}:
155155
- job: E2ETestFabric${{ matrix.Name }}
156156
displayName: E2E Test App Fabric ${{ matrix.Name }}
157157

.ado/jobs/integration-test.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,42 @@ parameters:
1212
default:
1313
- BuildEnvironment: PullRequest
1414
Matrix:
15-
- Name: X64ReleaseHermes
15+
- Name: X64Release
1616
BuildPlatform: x64
1717
BuildConfiguration: Release
1818
DeployOptions:
19-
UseHermes: true
2019
- BuildEnvironment: Continuous
2120
Matrix:
2221
- Name: Arm64Debug
2322
BuildPlatform: ARM64
2423
BuildConfiguration: Debug
2524
DeployOptions: --no-deploy # We don't have Arm agents
26-
UseHermes: false
2725
- Name: X64WebDebug
2826
BuildPlatform: x64
2927
BuildConfiguration: Debug
3028
DeployOptions:
31-
UseHermes: false
32-
- Name: X64ReleaseHermes
29+
- Name: X86WebDebug
30+
BuildPlatform: x86
31+
BuildConfiguration: Debug
32+
DeployOptions:
33+
- Name: X64Release
3334
BuildPlatform: x64
3435
BuildConfiguration: Release
3536
DeployOptions:
36-
UseHermes: true
37-
- Name: X86WebDebug
37+
- Name: X86Release
3838
BuildPlatform: x86
39-
BuildConfiguration: Debug
39+
BuildConfiguration: Release
40+
DeployOptions:
41+
- Name: X64ReleaseChakra
42+
BuildPlatform: x64
43+
BuildConfiguration: Release
4044
DeployOptions:
41-
UseHermes: false
42-
- Name: X86ReleaseHermes
45+
UseChakra: true
46+
- Name: X86ReleaseChakra
4347
BuildPlatform: x86
4448
BuildConfiguration: Release
4549
DeployOptions:
46-
UseHermes: true
50+
UseChakra: true
4751

4852
jobs:
4953
- ${{ each config in parameters.buildMatrix }}:
@@ -81,7 +85,7 @@ jobs:
8185
parameters:
8286
package: packages/integration-test-app
8387
feature: UseHermes
84-
value: ${{ matrix.UseHermes }}
88+
value: ${{ not(coalesce(matrix.UseChakra, false))}}
8589

8690
- ${{ if eq(matrix.BuildConfiguration, 'Debug') }}:
8791
# The build is more likely to crash after we've started other bits that

.ado/templates/react-native-init.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ parameters:
2424
- name: additionalRunArguments
2525
type: string
2626
default: ''
27+
- name: useChakra
28+
type: boolean
29+
default: false
2730
- name: useNuGet
2831
type: boolean
2932
default: false
@@ -102,6 +105,12 @@ steps:
102105
workingDirectory: $(Agent.BuildDirectory)\testcli
103106
env:
104107
npm_config_registry: http://localhost:4873
108+
109+
- template: set-experimental-feature.yml
110+
parameters:
111+
package: ..\testcli
112+
feature: UseHermes
113+
value: ${{ not(parameters.UseChakra) }}
105114

106115
- ${{ if eq(parameters.projectType, 'app') }}:
107116
- powershell: |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Make Hermes the default JS engine",
4+
"packageName": "@react-native-windows/cli",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Make Hermes the default JS engine",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/@react-native-windows/cli/src/commands/config/configUtils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,28 @@ export function tryFindPropertyValue(
300300
return null;
301301
}
302302

303+
/**
304+
* Search for the given property in the project contents and return its value.
305+
* @param projectContents The XML project contents.
306+
* @param propertyName The property to look for.
307+
* @return The value of the tag if it exists.
308+
*/
309+
export function tryFindPropertyValueAsBoolean(
310+
projectContents: Node,
311+
propertyName: string,
312+
): boolean | null {
313+
const rawValue = tryFindPropertyValue(projectContents, propertyName);
314+
315+
switch (rawValue) {
316+
case 'true':
317+
return true;
318+
case 'false':
319+
return false;
320+
default:
321+
return null;
322+
}
323+
}
324+
303325
export function findPropertyValue(
304326
projectContents: Node,
305327
propertyName: string,

packages/@react-native-windows/cli/src/generator-windows/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import findUp from 'find-up';
1616
import {
1717
readProjectFile,
1818
findPropertyValue,
19+
tryFindPropertyValueAsBoolean,
1920
} from '../commands/config/configUtils';
2021

2122
import {
@@ -130,6 +131,27 @@ export async function copyProjectTemplateAndReplace(
130131
console.log('Using experimental NuGet dependency.');
131132
}
132133

134+
const experimentalPropsPath = path.join(
135+
destPath,
136+
windowsDir,
137+
'ExperimentalFeatures.props',
138+
);
139+
140+
let existingUseHermes: boolean | null = null;
141+
if (fs.existsSync(experimentalPropsPath)) {
142+
existingUseHermes = tryFindPropertyValueAsBoolean(
143+
readProjectFile(experimentalPropsPath),
144+
'UseHermes',
145+
);
146+
}
147+
148+
if (existingUseHermes === false) {
149+
console.warn(
150+
'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.',
151+
);
152+
}
153+
options.useHermes = true;
154+
133155
if (options.useWinUI3) {
134156
throw new CodedError(
135157
'IncompatibleOptions',

packages/e2e-test-app/windows/ExperimentalFeatures.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33

44
<PropertyGroup Label="Microsoft.ReactNative Experimental Features">
5-
<UseHermes>false</UseHermes>
5+
<UseHermes>true</UseHermes>
66
<EnableSourceLink>true</EnableSourceLink>
77
<ReactExperimentalFeaturesSet>true</ReactExperimentalFeaturesSet>
88
</PropertyGroup>

packages/integration-test-app/windows/ExperimentalFeatures.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33

44
<PropertyGroup Label="Microsoft.ReactNative Experimental Features">
5-
<UseHermes>false</UseHermes>
5+
<UseHermes>true</UseHermes>
66
<EnableSourceLink>true</EnableSourceLink>
77
<ReactExperimentalFeaturesSet>true</ReactExperimentalFeaturesSet>
88
</PropertyGroup>

0 commit comments

Comments
 (0)