Skip to content
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

fix(gatsby): Fix various small DEV_SSR bugs exposed in development_runtime tests (#29720) #29866

Merged
merged 1 commit into from
Mar 1, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/gatsby/cache-dir/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,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 @@ -59,8 +59,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