Skip to content

Commit

Permalink
add async execution placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Dec 7, 2024
1 parent 780fc0e commit 4e9eb8c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/next/src/server/after/stitch-after-callstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function getStitchedAfterCallstack(
if (hasPromiseMarkerFrame(frames)) {
return
}
frames.unshift(createAsyncPlaceholderFrame())
userFramesFromTaskCallers = userFramesFromTaskCallers.concat(frames)
}
}
Expand All @@ -139,6 +140,8 @@ function getStitchedAfterCallstack(
return
}

rootCallerFrames.unshift(createAsyncPlaceholderFrame())

const reactBottomFrameIndex = rootCallerFrames.findIndex(
(frame) => frame.methodName === 'react-stack-bottom-frame'
)
Expand All @@ -162,6 +165,16 @@ function getStitchedAfterCallstack(
)
}

function createAsyncPlaceholderFrame() {
return {
methodName: '<async execution of unstable_after>',
file: '<anonymous>',
lineNumber: null,
column: null,
arguments: [],
}
}

function hasPromiseMarkerFrame(frames: StackFrame[]) {
return frames.some(isPromiseMarkerFrame)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ describe('after - error stacks', () => {
"An error occurred in a function passed to \`after()\`: Error: kaboom
at throws (_.js:0:0)
at aboveThrows (_.js:0:0)
at <async execution of unstable_after> (<anonymous>)
at nestedHelper (_.js:0:0)
at aboveNestedHelper (_.js:0:0)
at <async execution of unstable_after> (<anonymous>)
at helper (_.js:0:0)
at Inner (_.js:0:0)
at Wrapper (_.js:0:0)
Expand All @@ -76,6 +78,7 @@ describe('after - error stacks', () => {
"An error occurred in a function passed to \`after()\`: Error: kaboom
at throws (_.js:0:0)
at <unknown> (_.js:0:0)
at <async execution of unstable_after> (<anonymous>)
at helper (_.js:0:0)
at Inner (_.js:0:0)
at Wrapper (_.js:0:0)
Expand All @@ -96,6 +99,7 @@ describe('after - error stacks', () => {
at throws (_.js:0:0)
at bar (_.js:0:0)
at <unknown> (_.js:0:0)
at <async execution of unstable_after> (<anonymous>)
at foo (_.js:0:0)
at Inner (_.js:0:0)
at Wrapper (_.js:0:0)
Expand All @@ -113,6 +117,7 @@ describe('after - error stacks', () => {
at throws (_.js:0:0)
at bar (_.js:0:0)
at <unknown> (_.js:0:0)
at <async execution of unstable_after> (<anonymous>)
at foo (_.js:0:0)
at async Inner (_.js:0:0)
at Wrapper (_.js:0:0)
Expand Down Expand Up @@ -187,6 +192,7 @@ describe('after - error stacks', () => {
An error occurred in a function passed to \`after()\`: Error: kaboom
at throws (_.js:0:0)
at zap (_.js:0:0)
at <async execution of unstable_after> (<anonymous>)
` + '\n'
)
})
Expand All @@ -202,6 +208,7 @@ describe('after - error stacks', () => {
An error occurred in a function passed to \`after()\`: Error: kaboom
at throws (_.js:0:0)
at zap (_.js:0:0)
at <async execution of unstable_after> (<anonymous>)
` + '\n'
)
})
Expand All @@ -215,6 +222,7 @@ describe('after - error stacks', () => {
at throws (_.js:0:0)
at zap (_.js:0:0)
at aboveZap (_.js:0:0)
at <async execution of unstable_after> (<anonymous>)
at bar (_.js:0:0)
at foo (_.js:0:0)
at async Inner (_.js:0:0)
Expand All @@ -233,6 +241,7 @@ describe('after - error stacks', () => {
at throws (_.js:0:0)
at zap (_.js:0:0)
at aboveZap (_.js:0:0)
at <async execution of unstable_after> (<anonymous>)
at bar (_.js:0:0)
at foo (_.js:0:0)
at Inner (_.js:0:0)
Expand All @@ -251,6 +260,7 @@ describe('after - error stacks', () => {
at throws (_.js:0:0)
at zap (_.js:0:0)
at aboveZap (_.js:0:0)
at <async execution of unstable_after> (<anonymous>)
at bar (_.js:0:0)
at foo (_.js:0:0)
at Inner (_.js:0:0)
Expand Down Expand Up @@ -288,7 +298,7 @@ const errorLogPrefixPattern = new RegExp(
const errorLogPattern = new RegExp(
errorLogPrefixPattern.source +
/[^\n]+\n/.source +
/(?:\s+at .*? \(.*?:\d+:\d+\)\n)+/.source
/(?:\s+at .*? \(.*?(?:\d+:\d+\))?\n)+/.source
)

/** Replace "(/some/file:123:456)" with "(/some/file/0:0)" */
Expand Down

0 comments on commit 4e9eb8c

Please sign in to comment.