Unverified Commit 17c05b67 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Always consider `captureOwnerStack` optional (#81370)

When running `next build` with a custom `NODE_ENV` (e.g. `test` or
`development`), the `captureOwnerStack` method is not defined and may
lead to errors if called. This change ensures that we only call
`captureOwnerStack` if it is defined, preventing potential runtime
errors.
parent 1a31db03
......@@ -664,7 +664,10 @@ function createErrorWithComponentOrOwnerStack(
componentStack: string
) {
const ownerStack =
process.env.NODE_ENV !== 'production' ? React.captureOwnerStack() : null
process.env.NODE_ENV !== 'production' && React.captureOwnerStack
? React.captureOwnerStack()
: null
const error = new Error(message)
error.stack = error.name + ': ' + message + (ownerStack ?? componentStack)
return error
......
......@@ -47,8 +47,11 @@ export function io(expression: string, type: ApiType) {
const errorWithStack = new Error(message)
if (process.env.NODE_ENV !== 'production') {
const ownerStack = workUnitStore.captureOwnerStack!()
if (
process.env.NODE_ENV !== 'production' &&
workUnitStore.captureOwnerStack
) {
const ownerStack = workUnitStore.captureOwnerStack()
if (ownerStack) {
// TODO: Instead of stitching the stacks here, we should log the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment