Skip to content

Commit 8dd3580

Browse files
authored
[dev-overlay] fix: proceed to get runtime error when fails to fetch original stack frames (#75743)
### Why? When fetch fails to get the original stack frames, the process to get the Runtime Errors fails. The fetch will likely fail on Storybook stories. | Before | After | |--------|--------| | ![CleanShot 2025-02-06 at 21 21 19](https://github.com/user-attachments/assets/7e136a02-8b1f-4ec0-8430-e02d919610c3) | ![CleanShot 2025-02-06 at 21 21 33](https://github.com/user-attachments/assets/5ce9f95f-f5a2-4738-b8c5-5152733aeab7) | ### How? Correctly reject when request fails so that it may be caught at `_getOriginalStackFrame()` and return the stack frame.
1 parent aabe188 commit 8dd3580

File tree

1 file changed

+17
-0
lines changed
  • packages/next/src/client/components/react-dev-overlay/internal/helpers

1 file changed

+17
-0
lines changed

packages/next/src/client/components/react-dev-overlay/internal/helpers/stack-frame.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,27 @@ export async function getOriginalStackFrames(
7676
isEdgeServer: type === 'edge-server',
7777
isAppDirectory: isAppDir,
7878
}
79+
7980
const res = await fetch('/__nextjs_original-stack-frames', {
8081
method: 'POST',
8182
body: JSON.stringify(req),
8283
})
84+
85+
// When fails to fetch the original stack frames, we reject here to be
86+
// caught at `_getOriginalStackFrame()` and return the stack frames so
87+
// that the error overlay can render.
88+
if (!res.ok || res.status === 204) {
89+
const reason = await res.text()
90+
return Promise.all(
91+
frames.map((frame) =>
92+
getOriginalStackFrame(frame, {
93+
status: 'rejected',
94+
reason: `Failed to fetch the original stack frames: ${reason}`,
95+
})
96+
)
97+
)
98+
}
99+
83100
const data = await res.json()
84101
return Promise.all(
85102
frames.map((frame, index) => getOriginalStackFrame(frame, data[index]))

0 commit comments

Comments
 (0)