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, an empty string or `null` is returned (see [Troubleshooting: The Owner Stack is empty](#the-owner-stack-is-empty-the-owner-stack-is-empty)).
57
57
58
58
#### Caveats {/*caveats*/}
59
59
60
-
- Owner Stacks are only available in development. `captureOwnerStack` will always return `null` outside of development.
60
+
- Owner Stacks are only available in development. `captureOwnerStack` will not be exported in production builds (see [`captureOwnerStack` is not available](#captureownerstack-is-not-available)).
61
61
62
62
<DeepDive>
63
63
@@ -388,13 +388,10 @@ export default function App() {
388
388
389
389
## Troubleshooting {/*troubleshooting*/}
390
390
391
-
### The Owner Stack is `null` {/*the-owner-stack-is-null*/}
392
-
393
-
`captureOwnerStack` was called outside of development builds. For performance reasons, React will not keep track of Owners in production.
394
-
395
391
### The Owner Stack is empty {/*the-owner-stack-is-empty*/}
396
392
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 to `captureOwnerStack()` returned `null` or the empty string (`''`).
394
+
Owner Stacks are not available 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.
398
395
399
396
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
397
<Sandpack>
@@ -408,7 +405,7 @@ export default function App() {
408
405
functionhandleEvent() {
409
406
// Calling it in a custom DOM event handler is too late.
@@ -438,4 +435,20 @@ export default function App() {
438
435
}
439
436
```
440
437
441
-
</Sandpack>
438
+
</Sandpack>
439
+
440
+
### `captureOwnerStack` is not available {/*captureownerstack-is-not-available*/}
441
+
442
+
`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.
443
+
444
+
```js
445
+
// Don't use named imports of `captureOwnerStack` in files that are bundled for development and production.
446
+
import {captureOwnerStack} from'react';
447
+
// Use a namespace import instead and access `captureOwnerStack` conditionally.
0 commit comments