Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[error overlay] fix infinite loop when frames are failed to fetch #75988

Merged
merged 4 commits into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,37 @@ export async function getOriginalStackFrames(
isAppDirectory: isAppDir,
}

const res = await fetch('/__nextjs_original-stack-frames', {
method: 'POST',
body: JSON.stringify(req),
})
let res: Response | undefined = undefined
let reason: string | undefined = undefined
try {
res = await fetch('/__nextjs_original-stack-frames', {
method: 'POST',
body: JSON.stringify(req),
})
} catch (e) {
reason = e + ''
}

// 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()
if (res && res.ok && res.status !== 204) {
const data = await res.json()
return Promise.all(
frames.map((frame) =>
getOriginalStackFrame(frame, {
status: 'rejected',
reason: `Failed to fetch the original stack frames: ${reason}`,
})
)
frames.map((frame, index) => getOriginalStackFrame(frame, data[index]))
)
} else {
if (res) {
reason = await res.text()
}
}

const data = await res.json()
return Promise.all(
frames.map((frame, index) => getOriginalStackFrame(frame, data[index]))
frames.map((frame) =>
getOriginalStackFrame(frame, {
status: 'rejected',
reason: `Failed to fetch the original stack frames ${reason ? `: ${reason}` : ''}`,
})
)
)
}

Expand Down
Loading