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
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ Experimental versions of React may contain bugs. Don't use them in production.
16
16
17
17
<Intro>
18
18
19
-
`captureOwnerStack` reads the current Owner Stack and returns it as a string if available.
19
+
`captureOwnerStack` reads the current Owner Stack in development and returns it as a string if available.
20
20
21
21
```js
22
22
conststack=captureOwnerStack();
@@ -56,6 +56,10 @@ function Component() {
56
56
If no Owner Stack is available, it returns an empty string.
57
57
Outside of development builds, `null` is returned.
58
58
59
+
#### Caveats {/*caveats*/}
60
+
61
+
- Owner Stacks are only available in development. `captureOwnerStack` will always return `null` outside of development.
62
+
59
63
## Owner Stack vs Component Stack {/*owner-stack-vs-component-stack*/}
60
64
61
65
The Owner Stack is different from the Component Stack available error handlers like [`errorInfo.componentStack` in `onUncaughtError`](/reference/react-dom/client/hydrateRoot#show-a-dialog-for-uncaught-errors).
@@ -162,3 +166,15 @@ const root = hydrateRoot(
162
166
);
163
167
root.render(<App />);
164
168
```
169
+
170
+
## Troubleshooting {/*troubleshooting*/}
171
+
172
+
### The Owner Stack is `null` {/*the-owner-stack-is-null*/}
173
+
174
+
`captureOwnerStack` was called outside of development builds.
175
+
For performance reasons, React will not keep track of Owners in production.
176
+
177
+
### The Owner Stack is empty {/*the-owner-stack-is-empty*/}
178
+
179
+
The call of `captureOwnerStack` happened outside of a React controlled function e.g. in a `setTimeout` callback.
180
+
During render, Effects, Events, and React error handlers (e.g. `hydrateRoot#options.onCaughtError`) Owner Stacks should be available.
0 commit comments