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 (#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)
  • Loading branch information
KyleAMathews authored and vladar committed Mar 1, 2021
1 parent 76f4f96 commit fe69daf
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 @@ -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

0 comments on commit fe69daf

Please sign in to comment.