Unverified Commit 8dd35800 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[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.
parent aabe1883
......@@ -76,10 +76,27 @@ export async function getOriginalStackFrames(
isEdgeServer: type === 'edge-server',
isAppDirectory: isAppDir,
}
const res = await fetch('/__nextjs_original-stack-frames', {
method: 'POST',
body: JSON.stringify(req),
})
// When fails to fetch the original stack frames, we reject here to be
// caught at `_getOriginalStackFrame()` and return the stack frames so
// that the error overlay can render.
if (!res.ok || res.status === 204) {
const reason = await res.text()
return Promise.all(
frames.map((frame) =>
getOriginalStackFrame(frame, {
status: 'rejected',
reason: `Failed to fetch the original stack frames: ${reason}`,
})
)
)
}
const data = await res.json()
return Promise.all(
frames.map((frame, index) => getOriginalStackFrame(frame, data[index]))
......
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