Skip to content

[Fiber] Fix DEV crash when use() is passed a non-extensible thenable - #37796

Merged
eps1lon merged 1 commit into
react:mainfrom
zhoubiao188:fix/use-frozen-thenable-dev-crash
Oct 12, 2026
Merged

eps1lon merged 1 commit into
react:mainfrom
zhoubiao188:fix/use-frozen-thenable-dev-crash

Conversation

@zhoubiao188

Copy link
Copy Markdown
Contributor

Fixes #37795

Summary

In DEV, trackUsedThenable infers async debug info for a used thenable by attaching a _debugInfo expando:

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.

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.
@meta-cla

meta-cla Bot commented Oct 8, 2026

Copy link
Copy Markdown

Hi @zhoubiao188!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Comparing: b618bbb...dc5b4f0

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 7.35 kB 7.35 kB -0.05% 1.96 kB 1.96 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 626.03 kB 626.03 kB = 110.63 kB 110.63 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 7.36 kB 7.36 kB -0.10% 1.97 kB 1.96 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 697.24 kB 697.24 kB = 122.06 kB 122.06 kB
facebook-www/ReactDOM-prod.classic.js = 715.27 kB 715.27 kB = 125.14 kB 125.14 kB
facebook-www/ReactDOM-prod.modern.js = 705.59 kB 705.59 kB = 123.56 kB 123.56 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by sizebot against dc5b4f0

@zhoubiao188

Copy link
Copy Markdown
Contributor Author

Hi @zhoubiao188!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

Thank you very much. I have signed it. Please review it again

@meta-cla

meta-cla Bot commented Oct 9, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed label Oct 9, 2026
@eps1lon eps1lon changed the title Fix DEV crash when use() is passed a non-extensible thenable [Fiber] Fix DEV crash when use() is passed a non-extensible thenable Oct 12, 2026
@eps1lon
eps1lon merged commit 259980d into react:main Oct 12, 2026
245 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 12, 2026
…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)
github-actions Bot pushed a commit that referenced this pull request Oct 12, 2026
…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)
eps1lon added a commit to vercel/next.js that referenced this pull request Oct 14, 2026
[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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: use() crashes in DEV with TypeError: Cannot add property _debugInfo when the thenable is frozen/non-extensible

2 participants