Repository navigation
Commit 2a2ccaa
Install globalEvalWithSourceUrl on bridgeless ReactInstance (#58718)
Summary:
**Problem:** On the New Architecture (bridgeless), fetching and evaluating a Metro split bundle in development (`lazy=true`, `import()`, `React.lazy()`) can fail with:
```
SyntaxError: Parsing source code unsupported: __d(function (global, require, _
```
The main bundle still loads.
**Root cause:** `global.globalEvalWithSourceUrl` is never installed on bridgeless. Bridge mode installs it in `JSIExecutor::initializeRuntime`.
```js
typeof global.globalEvalWithSourceUrl
// bridgeless: "undefined"
// bridge: "function"
```
The debug loader (`Libraries/Core/Devtools/loadBundleFromServer.js`) prefers that helper and only falls back to JS `eval()` when it is missing. The two paths are not equivalent in Hermes:
- `eval()` / `Function` go through `evalInEnvironment`, which raises `Parsing source code unsupported` when `RuntimeConfig::EnableEval` is false (and, on legacy Hermes, when the engine is built lean).
- `globalEvalWithSourceUrl` goes through `Runtime::evaluateJavaScript`, the same entry point used to run the main bundle. It is not gated by `EnableEval`, and it attaches the given source URL to stack traces.
So on a runtime where `EnableEval` is off (or the engine is lean), the main bundle loads but every split bundle falls into `eval()` and throws. Bridgeless has no way to reach the JSI path from JS today.
**Fix:** Port the existing `JSIExecutor` binding into `ReactInstance::initializeRuntime` so bridgeless exposes the same helper.
## Changelog:
[General] [Fixed] - Install globalEvalWithSourceUrl on bridgeless ReactInstance so debug bundle loaders can evaluate split bundles via JSI instead of eval()
Pull Request resolved: #58718
Test Plan:
1. `ReactInstanceTest.testGlobalEvalWithSourceUrlIsInstalled`: helper is absent before `initializeRuntime` and present after.
2. `ReactInstanceTest.testGlobalEvalWithSourceUrlMatchesEvalWhenEvalIsEnabled`: with the default `RuntimeConfig`, `eval('1 + 2')` and `globalEvalWithSourceUrl('1 + 2', 'chunk.js')` both return `3`.
3. `ReactInstanceWithoutEvalTest.testGlobalEvalWithSourceUrlWorksWhenEvalIsDisabled`: runtime built with `RuntimeConfig::Builder().withEnableEval(false)`; `eval('1 + 2')` throws `Parsing source code unsupported`, `globalEvalWithSourceUrl('1 + 2', 'chunk.js')` returns `3`.
4. Fantom `Libraries/Core/Devtools/__tests__/globalEvalWithSourceUrl-itest.js`: helper is installed on bridgeless; `eval()` and the helper evaluate the same source to the same result; an error thrown from the helper carries the given source URL in its stack while the `eval()` one does not; wrong arity throws.
5. In a bridgeless debug app, `typeof global.globalEvalWithSourceUrl` is `'function'` and a `React.lazy(() => import('./SomeModule'))` split bundle loads without `Parsing source code unsupported`.
Reviewed By: fabriziocucci
Differential Revision: D122329977
Pulled By: javache
fbshipit-source-id: 789294c7806a331828effd407588208a55e1d9a31 parent 44ffdba commit 2a2ccaa
3 files changed
Lines changed: 168 additions & 2 deletions
File tree
- packages/react-native
- Libraries/Core/Devtools/__tests__
- ReactCommon/react/runtime
- tests/cxx
Lines changed: 82 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 | + | |
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
461 | 494 | | |
462 | 495 | | |
463 | 496 | | |
| |||
Lines changed: 53 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
121 | 125 | | |
122 | | - | |
123 | | - | |
| 126 | + | |
| 127 | + | |
124 | 128 | | |
125 | 129 | | |
126 | 130 | | |
| |||
255 | 259 | | |
256 | 260 | | |
257 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
258 | 309 | | |
259 | 310 | | |
260 | 311 | | |
| |||
0 commit comments