Commit b4b229f
fix(node-renderer): expose performance in VM context when supportModules (#3158)
## Summary
- Adds `performance` to the default globals injected into the node
renderer's VM context when `supportModules: true`.
- React 19's development build of `React.lazy` calls `performance.now()`
inside `lazyInitializer`, which threw `ReferenceError: performance is
not defined` without this — making `React.lazy` unusable in dev unless
users manually passed `performance` via `additionalContext`.
- Updates the `Config` JSDoc, the `js-configuration.md` docs, and the
`CHANGELOG`, and adds a regression test.
Fixes #3154.
## Notes
The reporter also raised a broader question about the recommended
pattern for `React.lazy` with streaming SSR and `LimitChunkCountPlugin({
maxChunks: 1 })` (intermittent Suspense resolution causing hydration
mismatches / React error #419). That's a separate, larger discussion and
is not addressed here — this PR only fixes the concrete `performance`
VM-context bug the reporter identified and worked around.
## Test plan
- [x] `pnpm --filter react-on-rails-pro-node-renderer exec jest vm.test`
— all 27 tests pass, including the new assertions that `performance` and
`performance.now` are defined in the VM when `supportModules` is
enabled.
- [x] `pnpm exec prettier --check` on the modified files — passes.
- [x] `pnpm -w run eslint` on the modified source files — passes.
Generated with Claude Code (https://claude.com/claude-code)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Low risk: adds one additional global (`performance`) to the VM context
behind the existing `supportModules` flag, plus doc/test updates; main
behavioral change is potential nondeterministic SSR output if app code
embeds `performance.now()` values.
>
> **Overview**
> Fixes React 19 dev SSR crashes by adding the host `performance` object
to the node renderer VM globals when `supportModules: true`, alongside
existing injected Node globals.
>
> Updates docs and JSDoc to reflect the new default global set and to
clarify that `stubTimers` does not stub `performance` (with guidance for
overriding via `additionalContext`), and extends VM tests to assert
`performance`/`performance.now` presence when enabled (and absence when
disabled).
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
54b4aaf. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Restored React 19 dev compatibility by ensuring the renderer VM
includes the performance global when module support is enabled,
preventing ReferenceError in lazy-loaded code.
* **Documentation**
* Clarified that performance is included in the VM globals when module
support is enabled and noted behavior relative to timer stubbing and SSR
determinism.
* **Tests**
* Updated tests to assert performance and performance.now availability
in the VM sandbox.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 0ced93f commit b4b229f
File tree
6 files changed
+33
-14
lines changed- docs/oss
- building-features/node-renderer
- migrating
- packages/react-on-rails-pro-node-renderer
- src
- worker
- tests
6 files changed
+33
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
818 | 818 | | |
819 | 819 | | |
820 | 820 | | |
821 | | - | |
| 821 | + | |
822 | 822 | | |
823 | 823 | | |
824 | 824 | | |
| |||
831 | 831 | | |
832 | 832 | | |
833 | 833 | | |
834 | | - | |
| 834 | + | |
835 | 835 | | |
836 | 836 | | |
837 | 837 | | |
838 | 838 | | |
839 | 839 | | |
840 | | - | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
841 | 844 | | |
842 | 845 | | |
843 | 846 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
218 | | - | |
219 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
220 | 221 | | |
221 | 222 | | |
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
225 | 226 | | |
226 | 227 | | |
| 228 | + | |
227 | 229 | | |
228 | 230 | | |
229 | 231 | | |
| |||
Lines changed: 18 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
52 | | - | |
| 55 | + | |
53 | 56 | | |
54 | 57 | | |
55 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
56 | 67 | | |
57 | 68 | | |
58 | 69 | | |
| |||
62 | 73 | | |
63 | 74 | | |
64 | 75 | | |
65 | | - | |
| 76 | + | |
66 | 77 | | |
67 | 78 | | |
68 | 79 | | |
| |||
73 | 84 | | |
74 | 85 | | |
75 | 86 | | |
76 | | - | |
| 87 | + | |
77 | 88 | | |
78 | 89 | | |
79 | 90 | | |
| |||
0 commit comments