Skip to content

Commit fe69daf

Browse files
KyleAMathewsvladar
authored andcommitted
fix(gatsby): Fix various small DEV_SSR bugs exposed in development_runtime tests (#29720)
* the dev server now returns 404s which would otherwise fail the tests * Correctly detect if there's any SSRed HTML as ___gatsby always has the focus wrapper child * Handle unicode paths like /안녕 * Properly escape paths with special characters in it * Enable DEV_SSR for everyone * Fix status in test * Revert to 20% rollout * revert changes for 100% rollout * test this (cherry picked from commit 114e006)
1 parent 76f4f96 commit fe69daf

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

packages/gatsby/cache-dir/app.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,13 @@ apiRunnerAsync(`onClientEntry`).then(() => {
120120

121121
const rootElement = document.getElementById(`___gatsby`)
122122

123+
const focusEl = document.getElementById(`gatsby-focus-wrapper`)
123124
const renderer = apiRunner(
124125
`replaceHydrateFunction`,
125126
undefined,
126127
// Client only pages have any empty body so we just do a normal
127128
// render to avoid React complaining about hydration mis-matches.
128-
document.getElementById(`___gatsby`).children.length === 0
129-
? ReactDOM.render
130-
: ReactDOM.hydrate
129+
focusEl && focusEl.children.length > 0 ? ReactDOM.hydrate : ReactDOM.render
131130
)[0]
132131

133132
let dismissLoadingIndicator

packages/gatsby/src/utils/dev-ssr/develop-html-route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export const route = ({ app, program, store }): any =>
1010
app.get(`*`, async (req, res, next) => {
1111
trackFeatureIsUsed(`GATSBY_EXPERIMENTAL_DEV_SSR`)
1212

13-
const pathObj = findPageByPath(store.getState(), req.path)
13+
const pathObj = findPageByPath(store.getState(), decodeURI(req.path))
1414

1515
if (!pathObj) {
1616
return next()
1717
}
1818

19-
await appendPreloadHeaders(req.path, res)
19+
await appendPreloadHeaders(pathObj.path, res)
2020

2121
const htmlActivity = report.phantomActivity(`building HTML for path`, {})
2222
htmlActivity.start()
@@ -152,7 +152,7 @@ export const route = ({ app, program, store }): any =>
152152
node.js, it errored.
153153
</p>
154154
<ul>
155-
<li><strong>URL path:</strong> <code>${req.path}</code></li>
155+
<li><strong>URL path:</strong> <code>${pathObj.path}</code></li>
156156
<li><strong>File path:</strong> <code>${error.filename}</code></li>
157157
</ul>
158158
<h3>error</h3>

packages/gatsby/src/utils/dev-ssr/render-dev-html.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ export const restartWorker = (htmlComponentRendererPath): void => {
5959

6060
const searchFileForString = (substring, filePath): Promise<boolean> =>
6161
new Promise(resolve => {
62+
const escapedSubString = substring.replace(/[.*+?^${}()|[\]\\]/g, `\\$&`)
63+
6264
// See if the chunk is in the newComponents array (not the notVisited).
63-
const chunkRegex = RegExp(`exports.ssrComponents.*${substring}.*}`, `gs`)
65+
const chunkRegex = RegExp(
66+
`exports.ssrComponents.*${escapedSubString}.*}`,
67+
`gs`
68+
)
6469
const stream = fs.createReadStream(filePath)
6570
let found = false
6671
stream.on(`data`, function (d) {

packages/gatsby/src/utils/develop-preload-headers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function appendPreloadHeaders(
4343
`Link`,
4444
`</${path.join(
4545
`page-data`,
46-
fixedPagePath(pagePath),
46+
encodeURI(fixedPagePath(pagePath)),
4747
`page-data.json`
4848
)}>; rel=preload; as=fetch ; crossorigin`
4949
)

0 commit comments

Comments
 (0)