-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby): handle search params in resource loader #33209
Conversation
|
||
// Check for initial page-load redirect | ||
maybeRedirect(window.location.pathname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was causing some race condition where runtime behaviour is not deterministic. Specifically
window.___webpackCompilationHash = page.page.webpackCompilationHash |
gatsby/packages/gatsby/cache-dir/navigation.js
Lines 105 to 112 in 17a3f9f
// window.___webpackCompilationHash gets set in production-app.js after navigationInit() is called | |
// So on a direct visit of a page with a browser redirect this check is truthy and thus the codepath is hit | |
// While the resource actually exists, but only too late | |
// TODO: This should probably be fixed by setting ___webpackCompilationHash before navigationInit() is called | |
if ( | |
pageResources.page.webpackCompilationHash !== | |
window.___webpackCompilationHash | |
) { |
@@ -75,7 +75,7 @@ describe(`Redirects`, () => { | |||
failOnStatusCode: false, | |||
}).waitForRouteChange() | |||
|
|||
cy.location(`pathname`).should(`equal`, `/redirect-search-hash/`) | |||
cy.location(`pathname`).should(`equal`, `/redirect-search-hash`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Result of https://github.com/gatsbyjs/gatsby/pull/33209/files#r717559851
Please note that with this change it is actually same as we check client navigation in
gatsby/e2e-tests/production-runtime/cypress/integration/redirects.js
Lines 62 to 71 in 17a3f9f
it(`should support hash parameter with Link component`, () => { | |
cy.visit(`/`, { | |
failOnStatusCode: false, | |
}).waitForRouteChange() | |
cy.getTestElement(`redirect-two-anchor`).click().waitForRouteChange() | |
cy.location(`pathname`).should(`equal`, `/redirect-search-hash`) | |
cy.location(`hash`).should(`equal`, `#anchor`) | |
cy.location(`search`).should(`equal`, ``) | |
}) |
And same for 2 following changes
|
||
return res.status(404).sendFile(`404.html`, { root }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was breaking some code paths in e2e/prod-runtime tests that were previously not exposed because engines were not generated (this PR adds first SSR pages, so this code path was finally hit in those tests).
Later we have request handler for matchPaths (SSG matchpaths, not handled by engine) and sending 404 was just blocking it. We still have final fallback 404 later in final request handler.
Co-authored-by: Dustin Schau <[email protected]>
const maybeQueryString = Object.entries(req.query) | ||
.map(([k, v]) => `${k}=${v}`) | ||
.join(`&`) | ||
if (maybeQueryString) { | ||
searchString = `?${maybeQueryString}` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can rewrite this into this:
const maybeQueryString = Object.entries(req.query) | |
.map(([k, v]) => `${k}=${v}`) | |
.join(`&`) | |
if (maybeQueryString) { | |
searchString = `?${maybeQueryString}` | |
} | |
searchString = new URL('http://localhost:8000/test?q=234').search |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test seems to catch what we want to catch and code looks fine so 👍
Co-authored-by: Dustin Schau <[email protected]>
Description
SSR allows making use of query params but our runtime is right now adjusted to make it work well:
gatsby-link
) just strips query params and make use ofpathname
[ch38142]