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
Copy file name to clipboardExpand all lines: src/content/reference/react/captureOwnerStack.md
+247-8Lines changed: 247 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,13 @@ function Component() {
47
47
48
48
`captureOwnerStack` returns `string | null`.
49
49
50
-
If no Owner Stack is available (outside of render, Effects, Events and React error handlers), it returns an empty string (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)).
- React error handlers ([React Root options](/reference/react-dom/client/createRoot#parameters)`onCaughtError`, `onRecoverableError`, and `onUncaughtError`)
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)).
// Keep in mind that in a real application, console.error can be
201
+
// called with multiple arguments which you should account for.
202
+
consoleMessage: args[0],
203
+
ownerStack,
204
+
});
205
+
};
206
+
```
207
+
208
+
If you intercept <CodeStepstep={1}>`console.error`</CodeStep> calls to highlight them in an error overlay, you can call <CodeStepstep={2}>`captureOwnerStack`</CodeStep> to include the Owner Stack.
### The Owner Stack is empty {/*the-owner-stack-is-empty*/}
297
495
298
-
The call of `captureOwnerStack` happened outside of a React controlled function e.g. in a `setTimeout` callback. During render, Effects, Events, and React error handlers (e.g. `hydrateRoot#options.onCaughtError`) Owner Stacks should be available.
496
+
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.
497
+
498
+
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.
0 commit comments