Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
dbc94523
Unverified
Commit
dbc94523
authored
Oct 24, 2024
by
Jiachi Liu
Committed by
GitHub
Oct 24, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable owner stack in experimental build (#71716)
parent
4ae3fc3e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
13 deletions
+37
-13
define-env-plugin.ts
packages/next/src/build/webpack/plugins/define-env-plugin.ts
+5
-5
app-index.tsx
packages/next/src/client/app-index.tsx
+2
-3
CallStackFrame.tsx
...verlay/internal/container/RuntimeError/CallStackFrame.tsx
+8
-1
stitched-error.ts
...ents/react-dev-overlay/internal/helpers/stitched-error.ts
+2
-4
capture-console-error.test.ts
...p-dir/capture-console-error/capture-console-error.test.ts
+20
-0
No files found.
packages/next/src/build/webpack/plugins/define-env-plugin.ts
View file @
dbc94523
...
@@ -143,6 +143,9 @@ export function getDefineEnv({
...
@@ -143,6 +143,9 @@ export function getDefineEnv({
const
nextPublicEnv
=
getNextPublicEnvironmentVariables
()
const
nextPublicEnv
=
getNextPublicEnvironmentVariables
()
const
nextConfigEnv
=
getNextConfigEnv
(
config
)
const
nextConfigEnv
=
getNextConfigEnv
(
config
)
const
isPPREnabled
=
checkIsAppPPREnabled
(
config
.
experimental
.
ppr
)
const
isDynamicIOEnabled
=
!!
config
.
experimental
.
dynamicIO
const
defineEnv
:
DefineEnv
=
{
const
defineEnv
:
DefineEnv
=
{
// internal field to identify the plugin config
// internal field to identify the plugin config
__NEXT_DEFINE_ENV
:
true
,
__NEXT_DEFINE_ENV
:
true
,
...
@@ -183,11 +186,8 @@ export function getDefineEnv({
...
@@ -183,11 +186,8 @@ export function getDefineEnv({
'process.env.__NEXT_APP_ISR_INDICATOR'
:
Boolean
(
'process.env.__NEXT_APP_ISR_INDICATOR'
:
Boolean
(
config
.
devIndicators
.
appIsrStatus
config
.
devIndicators
.
appIsrStatus
),
),
'process.env.__NEXT_PPR'
:
checkIsAppPPREnabled
(
config
.
experimental
.
ppr
),
'process.env.__NEXT_PPR'
:
isPPREnabled
,
'process.env.__NEXT_DYNAMIC_IO'
:
!!
config
.
experimental
.
dynamicIO
,
'process.env.__NEXT_DYNAMIC_IO'
:
isDynamicIOEnabled
,
'process.env.__NEXT_REACT_OWNER_STACK'
:
Boolean
(
config
.
experimental
.
reactOwnerStack
),
'process.env.__NEXT_AFTER'
:
config
.
experimental
.
after
??
false
,
'process.env.__NEXT_AFTER'
:
config
.
experimental
.
after
??
false
,
'process.env.NEXT_DEPLOYMENT_ID'
:
config
.
deploymentId
||
false
,
'process.env.NEXT_DEPLOYMENT_ID'
:
config
.
deploymentId
||
false
,
'process.env.__NEXT_FETCH_CACHE_KEY_PREFIX'
:
fetchCacheKeyPrefix
??
''
,
'process.env.__NEXT_FETCH_CACHE_KEY_PREFIX'
:
fetchCacheKeyPrefix
??
''
,
...
...
packages/next/src/client/app-index.tsx
View file @
dbc94523
...
@@ -27,8 +27,6 @@ import { MissingSlotContext } from '../shared/lib/app-router-context.shared-runt
...
@@ -27,8 +27,6 @@ import { MissingSlotContext } from '../shared/lib/app-router-context.shared-runt
/// <reference types="react-dom/experimental" />
/// <reference types="react-dom/experimental" />
const
isReactOwnerStackEnabled
=
!!
process
.
env
.
__NEXT_REACT_OWNER_STACK
const
appElement
:
HTMLElement
|
Document
|
null
=
document
const
appElement
:
HTMLElement
|
Document
|
null
=
document
const
encoder
=
new
TextEncoder
()
const
encoder
=
new
TextEncoder
()
...
@@ -234,7 +232,8 @@ export function hydrate() {
...
@@ -234,7 +232,8 @@ export function hydrate() {
const
hasMissingTags
=
!!
rootLayoutMissingTags
?.
length
const
hasMissingTags
=
!!
rootLayoutMissingTags
?.
length
const
errorCallbacks
=
const
errorCallbacks
=
isReactOwnerStackEnabled
&&
process
.
env
.
NODE_ENV
!==
'production'
typeof
(
React
as
any
).
captureOwnerStack
===
'function'
&&
process
.
env
.
NODE_ENV
!==
'production'
?
{
?
{
onCaughtError
,
onCaughtError
,
onUncaughtError
,
onUncaughtError
,
...
...
packages/next/src/client/components/react-dev-overlay/internal/container/RuntimeError/CallStackFrame.tsx
View file @
dbc94523
...
@@ -28,6 +28,13 @@ export const CallStackFrame: React.FC<{
...
@@ -28,6 +28,13 @@ export const CallStackFrame: React.FC<{
// e.g. (app-pages-browser)/./app/page.tsx -> ./app/page.tsx
// e.g. (app-pages-browser)/./app/page.tsx -> ./app/page.tsx
const
formattedMethod
=
f
.
methodName
.
replace
(
/^
\([\w
-
]
+
\)\/
/
,
''
)
const
formattedMethod
=
f
.
methodName
.
replace
(
/^
\([\w
-
]
+
\)\/
/
,
''
)
// Formatted file source could be empty. e.g. <anonymous> will be formatted to empty string,
// we'll skip rendering the frame in this case.
const
fileSource
=
getFrameSource
(
f
)
if
(
!
fileSource
)
{
return
null
}
return
(
return
(
<
div
data
-
nextjs
-
call
-
stack
-
frame
>
<
div
data
-
nextjs
-
call
-
stack
-
frame
>
<
h3
data
-
nextjs
-
frame
-
expanded=
{
Boolean
(
frame
.
expanded
)
}
>
<
h3
data
-
nextjs
-
frame
-
expanded=
{
Boolean
(
frame
.
expanded
)
}
>
...
@@ -40,7 +47,7 @@ export const CallStackFrame: React.FC<{
...
@@ -40,7 +47,7 @@ export const CallStackFrame: React.FC<{
onClick=
{
open
}
onClick=
{
open
}
title=
{
hasSource
?
'Click to open in your editor'
:
undefined
}
title=
{
hasSource
?
'Click to open in your editor'
:
undefined
}
>
>
<
span
>
{
getFrameSource
(
f
)
}
</
span
>
<
span
>
{
fileSource
}
</
span
>
<
svg
<
svg
xmlns=
"http://www.w3.org/2000/svg"
xmlns=
"http://www.w3.org/2000/svg"
viewBox=
"0 0 24 24"
viewBox=
"0 0 24 24"
...
...
packages/next/src/client/components/react-dev-overlay/internal/helpers/stitched-error.ts
View file @
dbc94523
import
React
from
'react'
import
React
from
'react'
import
isError
from
'../../../../../lib/is-error'
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
=
'react-stack-bottom-frame'
const
REACT_ERROR_STACK_BOTTOM_FRAME_REGEX
=
new
RegExp
(
const
REACT_ERROR_STACK_BOTTOM_FRAME_REGEX
=
new
RegExp
(
`(at
${
REACT_ERROR_STACK_BOTTOM_FRAME
}
)|(
${
REACT_ERROR_STACK_BOTTOM_FRAME
}
\\@)`
`(at
${
REACT_ERROR_STACK_BOTTOM_FRAME
}
)|(
${
REACT_ERROR_STACK_BOTTOM_FRAME
}
\\@)`
)
)
export
function
getReactStitchedError
<
T
=
unknown
>
(
err
:
T
):
Error
|
T
{
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
return
err
}
}
...
@@ -31,7 +29,7 @@ export function getReactStitchedError<T = unknown>(err: T): Error | T {
...
@@ -31,7 +29,7 @@ export function getReactStitchedError<T = unknown>(err: T): Error | T {
newError
.
stack
=
newStack
newError
.
stack
=
newStack
// Avoid duplicate overriding stack frames
// Avoid duplicate overriding stack frames
const
ownerStack
=
captureOwnerStack
()
const
ownerStack
=
(
React
as
any
).
captureOwnerStack
()
if
(
ownerStack
&&
newStack
.
endsWith
(
ownerStack
)
===
false
)
{
if
(
ownerStack
&&
newStack
.
endsWith
(
ownerStack
)
===
false
)
{
newStack
+=
ownerStack
newStack
+=
ownerStack
// Override stack
// Override stack
...
...
test/development/app-dir/capture-console-error/capture-console-error.test.ts
View file @
dbc94523
...
@@ -8,6 +8,8 @@ import {
...
@@ -8,6 +8,8 @@ import {
waitForAndOpenRuntimeError
,
waitForAndOpenRuntimeError
,
}
from
'next-test-utils'
}
from
'next-test-utils'
const
isReactExperimental
=
process
.
env
.
__NEXT_EXPERIMENTAL_PPR
===
'true'
async
function
getRedboxResult
(
browser
:
any
)
{
async
function
getRedboxResult
(
browser
:
any
)
{
const
description
=
await
getRedboxDescription
(
browser
)
const
description
=
await
getRedboxDescription
(
browser
)
const
callStacks
=
await
getRedboxCallStack
(
browser
)
const
callStacks
=
await
getRedboxCallStack
(
browser
)
...
@@ -44,6 +46,24 @@ describe('app-dir - capture-console-error', () => {
...
@@ -44,6 +46,24 @@ describe('app-dir - capture-console-error', () => {
"description": "trigger an console <error>",
"description": "trigger an console <error>",
"source": "app/browser/event/page.js (7:17) @ onClick
"source": "app/browser/event/page.js (7:17) @ onClick
5 | <button
6 | onClick={() => {
> 7 | console.error('trigger an console <%s>', 'error')
| ^
8 | }}
9 | >
10 | click to error",
}
`
)
}
else
if
(
isReactExperimental
)
{
expect
(
result
).
toMatchInlineSnapshot
(
`
{
"callStacks": "button
app/browser/event/page.js (5:6)",
"count": 1,
"description": "trigger an console <error>",
"source": "app/browser/event/page.js (7:17) @ error
5 | <button
5 | <button
6 | onClick={() => {
6 | onClick={() => {
> 7 | console.error('trigger an console <%s>', 'error')
> 7 | console.error('trigger an console <%s>', 'error')
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment