Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 19 additions & 1 deletion integration-tests/ssr/__tests__/__snapshots__/ssr.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,23 @@ exports[`SSR it generates an error page correctly 1`] = `
<span style=\\"font-weight:normal;opacity:1;color:#452475;background:#fdfaf6;\\"> <span style=\\"color:#527713;\\"> | </span> <span style=\\"color:#096fb3;\\"><span style=\\"font-weight:bold;\\">^</span></span></span>
<span style=\\"font-weight:normal;opacity:1;color:#452475;background:#fdfaf6;\\"> <span style=\\"color:#527713;\\"> 5 | </span></span>
<span style=\\"font-weight:normal;opacity:1;color:#452475;background:#fdfaf6;\\"> <span style=\\"color:#527713;\\"> 6 | </span> <span style=\\"color:#006500;\\">return</span> <span style=\\"color:#DB3A00;\\"><</span><span style=\\"color:#DB3A00;\\">div</span><span style=\\"color:#DB3A00;\\">></span>hi<span style=\\"color:#DB3A00;\\"><</span><span style=\\"color:#DB3A00;\\">/</span><span style=\\"color:#DB3A00;\\">div</span><span style=\\"color:#DB3A00;\\">></span></span>
<span style=\\"font-weight:normal;opacity:1;color:#452475;background:#fdfaf6;\\"> <span style=\\"color:#527713;\\"> 7 | </span>}</span></pre>"
<span style=\\"font-weight:normal;opacity:1;color:#452475;background:#fdfaf6;\\"> <span style=\\"color:#527713;\\"> 7 | </span>}</span></pre>
<p>For help debugging SSR errors, see this docs page: <a
href=\\"https://www.gatsbyjs.com/docs/debugging-html-builds/\\">https://www.gatsbyjs.com/docs/debugging-html-builds/</a></p>
<h3>Skip SSR</h3>
<p>If you don't wish to fix the SSR error at the moment, press the
button below to reload the page without attempting SSR</p>
<p><strong>Note</strong>: this error will show up in when you build your site so must be fixed before then.</p>
<p><strong>Caveat</strong>: SSR errors in module scope i.e. outside of your components can't be skipped so will need fixed before you can continue</p>
<button onclick='refreshWithQueryString()'>Skip SSR</button>
<script>
function refreshWithQueryString() {
if ('URLSearchParams' in window) {
var searchParams = new URLSearchParams(window.location.search);
searchParams.set(\\"skip-ssr\\", \\"true\\");
window.location.search = searchParams.toString();
}
}
</script>
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Object {
<span style=\\"font-weight:normal;opacity:1;color:#452475;background:#fdfaf6;\\"> <span style=\\"color:#527713;\\"> 17 | </span> let tags</span>
<span style=\\"font-weight:normal;opacity:1;color:#452475;background:#fdfaf6;\\"> <span style=\\"color:#527713;\\"> 18 | </span> let tagsSection</span>
<span style=\\"font-weight:normal;opacity:1;color:#452475;background:#fdfaf6;\\"> <span style=\\"color:#527713;\\"> 19 | </span> <span style=\\"color:#006500;\\">if</span> (<span style=\\"color:#006500;\\">this</span><span style=\\"color:#DB3A00;\\">.</span>props<span style=\\"color:#DB3A00;\\">.</span>data<span style=\\"color:#DB3A00;\\">.</span>markdownRemark<span style=\\"color:#DB3A00;\\">.</span>fields<span style=\\"color:#DB3A00;\\">.</span>tagSlugs) {</span>",
"filename": "develop-html-route.ts",
"filename": "fixtures/blog-post.js",
"line": 16,
"message": "window is not defined",
"row": 17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ Object {
],
"message": "The following flags are active:
- ALL_COMMANDS · (Umbrella Issue (test)) · test

There are 5 other flags available that you might be interested in:
- FAST_DEV · Enable all experiments aimed at improving develop server start time
- DEV_SSR · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/28138)) · SSR pages on full reloads during develop. Helps you detect SSR bugs and fix them without needing to do full builds.
- QUERY_ON_DEMAND · (Umbrella Issue (https://github.com/gatsbyjs/gatsby/discussions/27620)) · Only run queries when needed instead of running all queries upfront. Speeds starting the develop server.
- ONLY_BUILDS · (Umbrella Issue (test)) · test
- YET_ANOTHER · (Umbrella Issue (test)) · test
",
"unknownFlagMessage": "The following flag(s) found in your gatsby-config.js are not known:
- FASTLY_DEV (did you mean: FAST_DEV)
Expand Down
25 changes: 25 additions & 0 deletions packages/gatsby/src/utils/dev-ssr/develop-html-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const route = ({ app, program, store }): any =>
const renderResponse = await renderDevHTML({
path: pathObj.path,
page: pathObj,
skipSsr: req.query[`skip-ssr`] || false,
store,
htmlComponentRendererPath: `${program.directory}/public/render-page.js`,
directory: program.directory,
Expand Down Expand Up @@ -62,6 +63,30 @@ export const route = ({ app, program, store }): any =>
if (error.codeFrame) {
errorHtml += `<pre style="background:#fdfaf6;padding:8px;">${error.codeFrame}</pre>`
}

// Add link to help page
errorHtml += `
<p>For help debugging SSR errors, see this docs page: <a
href="https://www.gatsbyjs.com/docs/debugging-html-builds/">https://www.gatsbyjs.com/docs/debugging-html-builds/</a></p>`

// Add skip ssr button
errorHtml += `
<h3>Skip SSR</h3>
<p>If you don't wish to fix the SSR error at the moment, press the
button below to reload the page without attempting SSR</p>
<p><strong>Note</strong>: this error will show up in when you build your site so must be fixed before then.</p>
<p><strong>Caveat</strong>: SSR errors in module scope i.e. outside of your components can't be skipped so will need fixed before you can continue</p>
<button onclick='refreshWithQueryString()'>Skip SSR</button>
<script>
function refreshWithQueryString() {
if ('URLSearchParams' in window) {
var searchParams = new URLSearchParams(window.location.search);
searchParams.set("skip-ssr", "true");
window.location.search = searchParams.toString();
}
}
</script>
`
res.status(500).send(errorHtml)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/dev-ssr/render-dev-html-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const parseError = function ({ err, directory, componentPath }) {
const type = err.type ? err.type : err.name

const data = {
filename: sysPath.relative(directory, componentPath),
filename: sysPath.relative(directory, filename),
message: message,
type: type,
stack: stack,
Expand Down
6 changes: 6 additions & 0 deletions packages/gatsby/src/utils/dev-ssr/render-dev-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const ensurePathComponentInSSRBundle = async (
export const renderDevHTML = ({
path,
page,
skipSsr = false,
store,
htmlComponentRendererPath,
directory,
Expand Down Expand Up @@ -156,6 +157,11 @@ export const renderDevHTML = ({
isClientOnlyPage = true
}

// If the user added the query string `skip-ssr`, we always just render an empty shell.
if (skipSsr) {
isClientOnlyPage = true
}

try {
const htmlString = await worker.renderHTML({
path,
Expand Down