You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- React error handlers ([React Root options](/reference/react-dom/client/createRoot#parameters)`onCaughtError`, `onRecoverableError`, and `onUncaughtError`)
55
55
56
-
If no Owner Stack is available, an empty string is returned (see [Troubleshooting: The Owner Stack is empty](#the-owner-stack-is-empty-the-owner-stack-is-empty)). Outside of development builds, `null` is returned (see [Troubleshooting: The Owner Stack is `null`](#the-owner-stack-is-null-the-owner-stack-is-null)).
56
+
If no Owner Stack is available, `null` is returned (see [Troubleshooting: The Owner Stack is `null`](#the-owner-stack-is-null)).
57
57
58
58
#### Caveats {/*caveats*/}
59
59
@@ -299,7 +299,7 @@ pre.nowrap {
299
299
<p>
300
300
<preid="error-body"></pre>
301
301
</p>
302
-
<h2class="-mb-20">Owner stack:</h4>
302
+
<h2class="-mb-20">Owner Stack:</h4>
303
303
<preid="error-owner-stack"class="nowrap"></pre>
304
304
<button
305
305
id="error-close"
@@ -390,11 +390,7 @@ export default function App() {
390
390
391
391
### The Owner Stack is `null` {/*the-owner-stack-is-null*/}
392
392
393
-
`captureOwnerStack` was called outside of development builds. For performance reasons, React will not keep track of Owners in production.
394
-
395
-
### The Owner Stack is empty {/*the-owner-stack-is-empty*/}
396
-
397
-
The call of `captureOwnerStack` happened outside of a React controlled function e.g. in a `setTimeout` callback, after a fetch or in a custom DOM event handler. During render, Effects, React event handlers, and React error handlers (e.g. `hydrateRoot#options.onCaughtError`) Owner Stacks should be available.
393
+
The call of `captureOwnerStack` happened outside of a React controlled function e.g. in a `setTimeout` callback, after a `fetch` call or in a custom DOM event handler. During render, Effects, React event handlers, and React error handlers (e.g. `hydrateRoot#options.onCaughtError`) Owner Stacks should be available.
398
394
399
395
In the example below, clicking the button will log an empty Owner Stack because `captureOwnerStack` was called during a custom DOM event handler. The Owner Stack must be captured earlier e.g. by moving the call of `captureOwnerStack` into the Effect body.
400
396
<Sandpack>
@@ -407,7 +403,7 @@ export default function App() {
407
403
// Should call `captureOwnerStack` here.
408
404
functionhandleEvent() {
409
405
// Calling it in a custom DOM event handler is too late.
@@ -438,4 +434,20 @@ export default function App() {
438
434
}
439
435
```
440
436
441
-
</Sandpack>
437
+
</Sandpack>
438
+
439
+
### `captureOwnerStack` is not available {/*captureownerstack-is-not-available*/}
440
+
441
+
`captureOwnerStack` is only exported in development builds. It will be `undefined` in production builds. If `captureOwnerStack` is used in files that are bundled for production and development, you should conditionally access it from a namespace import.
442
+
443
+
```js
444
+
// Don't use named imports of `captureOwnerStack` in files that are bundled for development and production.
445
+
import {captureOwnerStack} from'react';
446
+
// Use a namespace import instead and access `captureOwnerStack` conditionally.
0 commit comments