Commit 6377bb8
Babel preset: Add Hermes V1 native runtime workarounds for hermes#1761
## Summary:
Three Babel plugins added to `@react-native/babel-preset` that work
around runtime codegen bugs in the bundled Hermes V1 (250829098.0.13,
branch cut 2025-08-29) by rewriting source patterns before they reach
the engine. Each plugin papers over a different bug that is fixed on
Hermes `static_h` but has not been backported to the V1 stable branch
(verified absent through the .0.15 stable tip; the only in-flight graft,
facebook/hermes#2030, is still open).
- `fix-hermes-v1-async-arrow-non-simple-params`:
facebook/hermes#1761 (fixed in static_h by 68bfb3a48b31, 2025-09-11).
Async arrow functions with destructured, defaulted, or rest parameters
silently resolve `await` with `undefined` while the function body
continues executing in the background. The plugin rewrites the params
to a simple identifier with inline destructuring so Hermes never sees
the buggy shape. Gated on `isHermesProfile && preserveAsync` since
`plugin-transform-async-to-generator` rewrites the pattern away when
`preserveAsync` is false.
- `fix-hermes-v1-class-in-finally`:
Fixed in static_h by 1e94fbe0ebb4 (2026-02-12). Class declarations
inside a `finally` block trip Hermes V1's variable caching path. The
plugin wraps them in an IIFE so the class lives in its own scope, and
preserves the inferred name of a class expression bound to a plain
identifier.
- `fix-hermes-v1-super-in-object-accessor`:
Fixed in static_h by 18a963465944 (2025-11-04). Object-literal getters
and setters using `super.x` trip the `genFunctionExpression` home
object path, which segfaults hermesc at compile time. The plugin marks
the accessor as computed with a string key, covering identifier,
string, and numeric keys.
All three gate on `isHermesProfile` and bail out fast on the common
case. The plugins are a direct port of work by @kitten (Phil Pluckthun,
Expo team) in `babel-preset-expo` (expo/expo#45601, MIT licensed). All
plugin design and implementation credit belongs to him. This PR carries
his work over to `@react-native/babel-preset` so bare React Native
consumers benefit from the same fix.
## Changelog:
[GENERAL] [FIXED] - Work around three Hermes V1 source-level codegen bugs in `@react-native/babel-preset` (async-arrow non-simple params, class-in-finally, super-in-object-accessor)
## Test Plan:
- 21 inline-snapshot test cases across three new test files verify the transformed output, the fast-bail behavior on irrelevant patterns, and the numeric-key and class-name edge cases.
- `yarn jest packages/react-native-babel-preset` clean (76 tests, 27 snapshots).
- Full repo `yarn test` clean (278 suites, 5692 tests passed, 1857 snapshots).
- `yarn lint`, `yarn format-check`, `yarn flow-check`, `yarn test-typescript`, `yarn featureflags --verify-unchanged`, `yarn build-types --validate` all clean.
- Existing `transform-snapshot-test` passes byte-identical: the kitchen-sink fixture has none of the buggy patterns so the new plugins do not change its output for any profile.
- Compiled the bug patterns through the bundled compiler (hermes-compiler 250829098.0.14): `get x() { return super.x }` and `get 0() { return super.x }` both segfault hermesc, while the transformed computed-key output compiles clean.
- Device repro at ramonclaudio/hermes-1761-repro: 55/55 PASS on iPhone 17 Pro / iOS 26.5 in Debug and Release.
## Caveats:
`fix-hermes-v1-class-in-finally` rewrites block-scoped `class`
declarations inside `finally` blocks to function-scoped `var`
initializers, matching the babel-preset-expo source. Observable only
when code in the same `finally` references the class before its
declaration or relies on its block scoping (rare). The same plugin shape
has shipped in `babel-preset-expo` and Expo SDK 56 without reported
regressions, but flagging in case Meta's internal test fleet surfaces an
edge case the OSS suite does not catch.
## References:
- facebook/hermes#1761 (root-cause issue, fixed in static_h)
- facebook/hermes#2030 (in-flight graft of the async-arrow fix onto the V1 stable branch, still open)
- expo/expo#45601 (source of the ported plugins, by @kitten)
- expo/expo#45592 (user-facing bug report on SDK 56 preview)
Co-authored-by: Phil Pluckthun <phil@kitten.sh>1 parent aea8785 commit 6377bb8
8 files changed
Lines changed: 774 additions & 0 deletions
File tree
- packages/react-native-babel-preset/src
- __tests__
- configs
Lines changed: 115 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
Lines changed: 181 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
0 commit comments