Skip to content

Commit

Permalink
fix(gatsby): Fix various small DEV_SSR bugs exposed in development_ru…
Browse files Browse the repository at this point in the history
…ntime 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
  • Loading branch information
KyleAMathews authored Mar 4, 2021
1 parent 6c6837b commit 890d5e5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 2 additions & 3 deletions packages/gatsby/cache-dir/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,13 @@ apiRunnerAsync(`onClientEntry`).then(() => {

const rootElement = document.getElementById(`___gatsby`)

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

let dismissLoadingIndicator
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby/src/utils/dev-ssr/develop-html-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export const route = ({ app, program, store }): any =>
app.get(`*`, async (req, res, next) => {
trackFeatureIsUsed(`GATSBY_EXPERIMENTAL_DEV_SSR`)

const pathObj = findPageByPath(store.getState(), req.path)
const pathObj = findPageByPath(store.getState(), decodeURI(req.path))

if (!pathObj) {
return next()
}

await appendPreloadHeaders(req.path, res)
await appendPreloadHeaders(pathObj.path, res)

const htmlActivity = report.phantomActivity(`building HTML for path`, {})
htmlActivity.start()
Expand Down Expand Up @@ -152,7 +152,7 @@ export const route = ({ app, program, store }): any =>
node.js, it errored.
</p>
<ul>
<li><strong>URL path:</strong> <code>${req.path}</code></li>
<li><strong>URL path:</strong> <code>${pathObj.path}</code></li>
<li><strong>File path:</strong> <code>${error.filename}</code></li>
</ul>
<h3>error</h3>
Expand Down
7 changes: 6 additions & 1 deletion packages/gatsby/src/utils/dev-ssr/render-dev-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ export const restartWorker = (htmlComponentRendererPath): void => {

const searchFileForString = (substring, filePath): Promise<boolean> =>
new Promise(resolve => {
const escapedSubString = substring.replace(/[.*+?^${}()|[\]\\]/g, `\\$&`)

// See if the chunk is in the newComponents array (not the notVisited).
const chunkRegex = RegExp(`exports.ssrComponents.*${substring}.*}`, `gs`)
const chunkRegex = RegExp(
`exports.ssrComponents.*${escapedSubString}.*}`,
`gs`
)
const stream = fs.createReadStream(filePath)
let found = false
stream.on(`data`, function (d) {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/develop-preload-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function appendPreloadHeaders(
`Link`,
`</${path.join(
`page-data`,
fixedPagePath(pagePath),
encodeURI(fixedPagePath(pagePath)),
`page-data.json`
)}>; rel=preload; as=fetch ; crossorigin`
)
Expand Down

0 comments on commit 890d5e5

Please sign in to comment.