Skip to content

Commit

Permalink
checking api if available
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Oct 23, 2024
1 parent 586acb7 commit 5a953b6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
3 changes: 0 additions & 3 deletions packages/next/src/build/webpack/plugins/define-env-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ export function getDefineEnv({

const isPPREnabled = checkIsAppPPREnabled(config.experimental.ppr)
const isDynamicIOEnabled = !!config.experimental.dynamicIO
const isOwnerStackEnabled = Boolean(config.experimental.reactOwnerStack)

const defineEnv: DefineEnv = {
// internal field to identify the plugin config
Expand Down Expand Up @@ -189,8 +188,6 @@ export function getDefineEnv({
),
'process.env.__NEXT_PPR': isPPREnabled,
'process.env.__NEXT_DYNAMIC_IO': isDynamicIOEnabled,
'process.env.__NEXT_REACT_OWNER_STACK':
isPPREnabled || isDynamicIOEnabled || isOwnerStackEnabled,
'process.env.__NEXT_AFTER': config.experimental.after ?? false,
'process.env.NEXT_DEPLOYMENT_ID': config.deploymentId || false,
'process.env.__NEXT_FETCH_CACHE_KEY_PREFIX': fetchCacheKeyPrefix ?? '',
Expand Down
5 changes: 2 additions & 3 deletions packages/next/src/client/app-index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import { MissingSlotContext } from '../shared/lib/app-router-context.shared-runt

/// <reference types="react-dom/experimental" />

const isReactOwnerStackEnabled = !!process.env.__NEXT_REACT_OWNER_STACK

const appElement: HTMLElement | Document | null = document

const encoder = new TextEncoder()
Expand Down Expand Up @@ -234,7 +232,8 @@ export function hydrate() {
const hasMissingTags = !!rootLayoutMissingTags?.length

const errorCallbacks =
isReactOwnerStackEnabled && process.env.NODE_ENV !== 'production'
typeof (React as any).captureOwnerStack === 'function' &&
process.env.NODE_ENV !== 'production'
? {
onCaughtError,
onUncaughtError,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React from 'react'
import isError from '../../../../../lib/is-error'

const captureOwnerStack = (React as any).captureOwnerStack || (() => '')

const REACT_ERROR_STACK_BOTTOM_FRAME = 'react-stack-bottom-frame'
const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX = new RegExp(
`(at ${REACT_ERROR_STACK_BOTTOM_FRAME} )|(${REACT_ERROR_STACK_BOTTOM_FRAME}\\@)`
)

export function getReactStitchedError<T = unknown>(err: T): Error | T {
if (!process.env.__NEXT_REACT_OWNER_STACK) {
if (typeof (React as any).captureOwnerStack !== 'function') {
return err
}

Expand All @@ -31,7 +29,7 @@ export function getReactStitchedError<T = unknown>(err: T): Error | T {
newError.stack = newStack

// Avoid duplicate overriding stack frames
const ownerStack = captureOwnerStack()
const ownerStack = (React as any).captureOwnerStack()
if (ownerStack && newStack.endsWith(ownerStack) === false) {
newStack += ownerStack
// Override stack
Expand Down

0 comments on commit 5a953b6

Please sign in to comment.