Repository navigation
[Fiber] Fix DEV crash when use() is passed a non-extensible thenable - #37796
Conversation
In DEV, trackUsedThenable infers debug info for a used thenable by attaching a _debugInfo expando. If the thenable was made non-extensible (e.g. a userspace-instrumented thenable frozen by a cache), the assignment throws a TypeError inside React and crashes the render. Skip the debug info instrumentation when the thenable doesn't allow new properties, mirroring the existing guard for frozen values in Flight's addAsyncInfo.
|
Hi @zhoubiao188! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
Comparing: b618bbb...dc5b4f0 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) Generated by sizebot against dc5b4f0 |
Thank you very much. I have signed it. Please review it again |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
…37796) Fixes #37795 ## Summary In DEV, `trackUsedThenable` infers async debug info for a used thenable by attaching a `_debugInfo` expando: ```js if (__DEV__ && thenable._debugInfo === undefined) { ... thenable._debugInfo = [{awaited: ioInfo}]; // throws on non-extensible objects ``` If the thenable was made non-extensible — e.g. a userspace-instrumented thenable (one that already carries a `status`) frozen by an immutable cache before being passed to `use()` — the assignment throws `TypeError: Cannot add property _debugInfo, object is not extensible` from inside React, crashing the render in development while the same code works in production. Since #37772 landed the `enableAsyncDebugInfo` flag for OSS, this path runs for every `use(thenable)` call in DEV, so such thenables now crash where they previously unwrapped fine. This PR skips the debug-info inference when the thenable doesn't allow new properties, mirroring the existing guard for frozen values in Flight's `addAsyncInfo` (`ReactFlightClient.js`), which already skips `_debugInfo` for frozen values ("Debug info is dropped for frozen elements"). Debug info is simply dropped for such thenables; `use()` unwraps the value normally. Note: a *non-instrumented* frozen promise (`use(Object.freeze(promise))`) still hits the pre-existing `pendingThenable.status = 'pending'` assignment in the `default` branch, which requires a different fix (e.g. a WeakMap fallback) — I've flagged that separately in the issue. ## How did you test this change? - Added a regression test in `ReactUse-test.js` (frozen, userspace-instrumented thenable passed to `use()`), which fails on `main` with `TypeError: Cannot add property _debugInfo, object is not extensible` at `ReactFiberThenable.js:192` and passes with this fix. - `yarn test packages/react-reconciler` — 77 suites, 1147 tests passed. - `yarn test packages/react-reconciler/src/__tests__/ReactUse-test.js` in both dev and `--prod` modes — 51 tests passed each. - Related suites pass: `ReactSuspense-test.internal.js`, `ReactSuspenseWithNoopRenderer-test.js`, `ReactLazy-test.internal.js`, `ReactConditionalUseWarning-test.js`, `ReactFlightAsyncDebugInfo-test.js`. - `npx eslint` and `npx prettier --check` clean on both changed files; `yarn flow dom-node` passes. Co-authored-by: zhoubiao188 <[email protected]> DiffTrain build for [259980d](259980d)
…37796) Fixes #37795 ## Summary In DEV, `trackUsedThenable` infers async debug info for a used thenable by attaching a `_debugInfo` expando: ```js if (__DEV__ && thenable._debugInfo === undefined) { ... thenable._debugInfo = [{awaited: ioInfo}]; // throws on non-extensible objects ``` If the thenable was made non-extensible — e.g. a userspace-instrumented thenable (one that already carries a `status`) frozen by an immutable cache before being passed to `use()` — the assignment throws `TypeError: Cannot add property _debugInfo, object is not extensible` from inside React, crashing the render in development while the same code works in production. Since #37772 landed the `enableAsyncDebugInfo` flag for OSS, this path runs for every `use(thenable)` call in DEV, so such thenables now crash where they previously unwrapped fine. This PR skips the debug-info inference when the thenable doesn't allow new properties, mirroring the existing guard for frozen values in Flight's `addAsyncInfo` (`ReactFlightClient.js`), which already skips `_debugInfo` for frozen values ("Debug info is dropped for frozen elements"). Debug info is simply dropped for such thenables; `use()` unwraps the value normally. Note: a *non-instrumented* frozen promise (`use(Object.freeze(promise))`) still hits the pre-existing `pendingThenable.status = 'pending'` assignment in the `default` branch, which requires a different fix (e.g. a WeakMap fallback) — I've flagged that separately in the issue. ## How did you test this change? - Added a regression test in `ReactUse-test.js` (frozen, userspace-instrumented thenable passed to `use()`), which fails on `main` with `TypeError: Cannot add property _debugInfo, object is not extensible` at `ReactFiberThenable.js:192` and passes with this fix. - `yarn test packages/react-reconciler` — 77 suites, 1147 tests passed. - `yarn test packages/react-reconciler/src/__tests__/ReactUse-test.js` in both dev and `--prod` modes — 51 tests passed each. - Related suites pass: `ReactSuspense-test.internal.js`, `ReactSuspenseWithNoopRenderer-test.js`, `ReactLazy-test.internal.js`, `ReactConditionalUseWarning-test.js`, `ReactFlightAsyncDebugInfo-test.js`. - `npx eslint` and `npx prettier --check` clean on both changed files; `yarn flow dom-node` passes. Co-authored-by: zhoubiao188 <[email protected]> DiffTrain build for [259980d](259980d)
[diff react/react@b618bbb4...07dde64d](react/react@b618bbb...07dde64) <details> <summary>React upstream changes</summary> - react/react#37710 - react/react#37814 - react/react#37778 - react/react#37688 - react/react#37796 </details> --------- Co-authored-by: next-js-bot[bot] <279046576+next-js-bot[bot]@users.noreply.github.com> Co-authored-by: Sebastian Sebbie Silbermann <[email protected]>
Fixes #37795
Summary
In DEV,
trackUsedThenableinfers async debug info for a used thenable by attaching a_debugInfoexpando:If the thenable was made non-extensible — e.g. a userspace-instrumented thenable (one that already carries a
status) frozen by an immutable cache before being passed touse()— the assignment throwsTypeError: Cannot add property _debugInfo, object is not extensiblefrom inside React, crashing the render in development while the same code works in production.Since #37772 landed the
enableAsyncDebugInfoflag for OSS, this path runs for everyuse(thenable)call in DEV, so such thenables now crash where they previously unwrapped fine.This PR skips the debug-info inference when the thenable doesn't allow new properties, mirroring the existing guard for frozen values in Flight's
addAsyncInfo(ReactFlightClient.js), which already skips_debugInfofor frozen values ("Debug info is dropped for frozen elements"). Debug info is simply dropped for such thenables;use()unwraps the value normally.Note: a non-instrumented frozen promise (
use(Object.freeze(promise))) still hits the pre-existingpendingThenable.status = 'pending'assignment in thedefaultbranch, which requires a different fix (e.g. a WeakMap fallback) — I've flagged that separately in the issue.How did you test this change?
ReactUse-test.js(frozen, userspace-instrumented thenable passed touse()), which fails onmainwithTypeError: Cannot add property _debugInfo, object is not extensibleatReactFiberThenable.js:192and passes with this fix.yarn test packages/react-reconciler— 77 suites, 1147 tests passed.yarn test packages/react-reconciler/src/__tests__/ReactUse-test.jsin both dev and--prodmodes — 51 tests passed each.ReactSuspense-test.internal.js,ReactSuspenseWithNoopRenderer-test.js,ReactLazy-test.internal.js,ReactConditionalUseWarning-test.js,ReactFlightAsyncDebugInfo-test.js.npx eslintandnpx prettier --checkclean on both changed files;yarn flow dom-nodepasses.