-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby): New overlay for DEV_SSR #31061
Changes from 7 commits
fa973ed
bbf8ece
fe66c81
1f6814c
862e9ca
d87f716
a8fb25e
08c3f66
87ed4fc
4ce68fa
a256448
52fdd95
051171b
0a87b43
938a29f
e8af19e
5f7d19e
e364f3a
81b4885
a7ba407
2143440
daf954c
9edb3f9
3b00bde
7615e6c
4ecfd3c
9eb5a5b
4430c5f
8826dc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -549,18 +549,12 @@ const errors = { | |
docsUrl: `https://www.gatsbyjs.com/docs/reference/gatsby-cli#new`, | ||
}, | ||
"11614": { | ||
text: ({ | ||
path, | ||
filePath, | ||
line, | ||
column, | ||
}): string => `The path "${path}" errored during SSR. | ||
|
||
Edit its component ${filePath}${ | ||
line ? `:${line}:${column}` : `` | ||
} to resolve the error.`, | ||
text: (context): string => | ||
stripIndent(`The path "${context.path}" errored during SSR. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it's a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. above comment addressed in 9eb5a5b |
||
Edit its component ${context.filePath}${ | ||
context.line ? `:${context.line}:${context.column}` : `` | ||
} to resolve the error.`), | ||
level: Level.WARNING, | ||
docsUrl: `https://gatsby.dev/debug-html`, | ||
}, | ||
// Watchdog | ||
"11701": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import * as React from "react" | ||
import { Overlay, Header, Body, Footer, HeaderOpenClose } from "./overlay" | ||
import { CodeFrame } from "./code-frame" | ||
import { prettifyStack, openInEditor, skipSSR, reloadPage } from "../utils" | ||
|
||
export function DevSsrError({ error }) { | ||
const { codeFrame, source, line } = error | ||
const decoded = prettifyStack(codeFrame) | ||
|
||
return ( | ||
<Overlay> | ||
<Header data-gatsby-error-type="build-error"> | ||
<div data-gatsby-overlay="header__cause-file"> | ||
<h1 id="gatsby-overlay-labelledby">Failed to server render (SSR)</h1> | ||
<span>{source}</span> | ||
</div> | ||
<HeaderOpenClose | ||
open={() => openInEditor(source, line)} | ||
dismiss={false} | ||
/> | ||
</Header> | ||
<Body> | ||
<p | ||
id="gatsby-overlay-describedby" | ||
data-gatsby-overlay="body__describedby" | ||
> | ||
React Components in Gatsby must render both successfully in the | ||
browser and in a Node.js environment. When we tried to render your | ||
page component in Node.js, it errored. | ||
</p> | ||
<h2>Source</h2> | ||
<CodeFrame decoded={decoded} /> | ||
<div data-gatsby-overlay="codeframe__bottom"> | ||
See our docs page for more info on SSR errors:{` `} | ||
<a href="https://www.gatsbyjs.com/docs/debugging-html-builds/"> | ||
Debugging HTML Builds | ||
</a> | ||
</div> | ||
<p> | ||
If you fixed the error, saved your file, and want to retry server | ||
rendering this page, please reload the page. | ||
</p> | ||
<button | ||
onClick={() => reloadPage()} | ||
data-gatsby-overlay="primary-button" | ||
> | ||
Reload page | ||
</button> | ||
<h2 style={{ marginTop: `var(--space)` }}>Skip SSR</h2> | ||
<p> | ||
If you don't wish to fix the SSR error at the moment, press the button | ||
below to reload the page without attempting to do SSR. | ||
</p> | ||
<button onClick={() => skipSSR()} data-gatsby-overlay="primary-button"> | ||
Skip SSR | ||
</button> | ||
<Footer> | ||
<span data-font-weight="bold">Note:</span> This error will show up | ||
during "gatsby build" so it must be fixed before then. SSR errors in | ||
module scope, e.g. outside of your own React components can't be | ||
skipped. | ||
</Footer> | ||
</Body> | ||
</Overlay> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,17 @@ | ||
import Anser from "anser" | ||
|
||
const enterRegex = /^\s$/ | ||
|
||
export function prettifyStack(errorInformation) { | ||
let txt | ||
if (Array.isArray(errorInformation)) { | ||
txt = errorInformation.join(`\n`) | ||
} else { | ||
txt = errorInformation | ||
} | ||
const generated = Anser.ansiToJson(txt, { | ||
return Anser.ansiToJson(txt, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was seeing weird behavior with removing the first line for all different errors. The underlying error format must have improved so this isn't necessary anymore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤞 This doesn't give me much confidence 😛 Maybe it happened because of #30801 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Should rephrase that: The indentation for the now first line was slightly incorrect as the previously existing new line wasn't there anymore. The PR you linked might have caused this, yeah |
||
remove_empty: true, | ||
use_classes: true, | ||
json: true, | ||
}) | ||
// Sometimes the first line/entry is an "Enter", so we need to filter this out | ||
const [firstLine, ...rest] = generated | ||
if (enterRegex.test(firstLine.content)) { | ||
return rest | ||
} | ||
return generated | ||
} | ||
|
||
export function openInEditor(file, lineNumber = 1) { | ||
|
@@ -31,6 +23,18 @@ export function openInEditor(file, lineNumber = 1) { | |
) | ||
} | ||
|
||
export function reloadPage() { | ||
window.location.reload() | ||
} | ||
|
||
export function skipSSR() { | ||
if (`URLSearchParams` in window) { | ||
const searchParams = new URLSearchParams(window.location.search) | ||
searchParams.set(`skip-ssr`, `true`) | ||
window.location.search = searchParams.toString() | ||
} | ||
} | ||
|
||
export function getCodeFrameInformation(stackTrace) { | ||
const callSite = stackTrace.find(CallSite => CallSite.getFileName()) | ||
if (!callSite) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't explicitly send
500
status anymore as other errors (runtime, build, graphql) also don't do that