Skip to content

Commit 890d5e5

Browse files
authored
fix(gatsby): Fix various small DEV_SSR bugs exposed in development_runtime tests (#29748)
* fix(gatsby): Fix various small DEV_SSR bugs exposed in development_runtime tests in v2 * Revert changes to tests for full rollout * Will this fix things?? * Better check for SSR
1 parent 6c6837b commit 890d5e5

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
@@ -117,14 +117,13 @@ apiRunnerAsync(`onClientEntry`).then(() => {
117117

118118
const rootElement = document.getElementById(`___gatsby`)
119119

120+
const focusEl = document.getElementById(`gatsby-focus-wrapper`)
120121
const renderer = apiRunner(
121122
`replaceHydrateFunction`,
122123
undefined,
123124
// Client only pages have any empty body so we just do a normal
124125
// render to avoid React complaining about hydration mis-matches.
125-
document.getElementById(`___gatsby`).children.length === 0
126-
? ReactDOM.render
127-
: ReactDOM.hydrate
126+
focusEl && focusEl.children.length > 0 ? ReactDOM.hydrate : ReactDOM.render
128127
)[0]
129128

130129
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
@@ -58,8 +58,13 @@ export const restartWorker = (htmlComponentRendererPath): void => {
5858

5959
const searchFileForString = (substring, filePath): Promise<boolean> =>
6060
new Promise(resolve => {
61+
const escapedSubString = substring.replace(/[.*+?^${}()|[\]\\]/g, `\\$&`)
62+
6163
// See if the chunk is in the newComponents array (not the notVisited).
62-
const chunkRegex = RegExp(`exports.ssrComponents.*${substring}.*}`, `gs`)
64+
const chunkRegex = RegExp(
65+
`exports.ssrComponents.*${escapedSubString}.*}`,
66+
`gs`
67+
)
6368
const stream = fs.createReadStream(filePath)
6469
let found = false
6570
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)