-
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4943ff2
initial
pieh 2640077
tmp
pieh 496c4cd
Merge remote-tracking branch 'origin/master' into query-params-loader
pieh 8fa1ca7
fix ensure-resources unit test
pieh 57e0464
Merge remote-tracking branch 'origin/master' into query-params-loader
pieh 14e0658
check search params only when pagepath contains them
pieh 6fea21c
strip and reattach search params when normalizing page path
pieh f89ac16
fix redirects race
pieh 2b31f2b
barebones ssr e2e tests
pieh f8610e8
add tests for dynamic paths
pieh a9cde80
fix(serve): let matchPath router handle path and don't 404 immediatelly
pieh 2568803
add same e2e tests to dev runtime tests
pieh 9a2e4db
revert debugging code
pieh 0d4d98f
drop no longer relevant comment
pieh ae0d158
fix(engine): only add search param to page path if it's SSR
pieh 5a6855e
Update e2e-tests/production-runtime/cypress/integration/ssr.js
pieh 8726ece
un-only also in dev runtime variant
pieh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
e2e-tests/development-runtime/cypress/integration/ssr.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const staticPath = `/ssr/static-path/` | ||
const paramPath = `/ssr/param-path/` | ||
const wildcardPath = `/ssr/wildcard-path/` | ||
|
||
describe(`Static path ('${staticPath}')`, () => { | ||
it(`Direct visit no query params`, () => { | ||
cy.visit(staticPath).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{}`) | ||
}) | ||
|
||
it(`Direct visit with query params`, () => { | ||
cy.visit(staticPath + `?foo=bar`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{}`) | ||
}) | ||
|
||
it(`Client navigation to same path with different query params`, () => { | ||
cy.visit(staticPath).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{}`) | ||
cy.window() | ||
.then(win => win.___navigate(staticPath + `?foo=bar`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{}`) | ||
cy.window() | ||
.then(win => win.___navigate(staticPath + `?foo=baz`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"baz"}`) | ||
cy.getTestElement(`params`).contains(`{}`) | ||
cy.window() | ||
.then(win => win.___navigate(staticPath)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{}`) | ||
}) | ||
}) | ||
|
||
describe(`Param path ('${paramPath}:param')`, () => { | ||
it(`Direct visit no query params`, () => { | ||
cy.visit(paramPath + `foo/`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{"param":"foo"}`) | ||
}) | ||
|
||
it(`Direct visit with query params`, () => { | ||
cy.visit(paramPath + `foo/` + `?foo=bar`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{"param":"foo"}`) | ||
}) | ||
|
||
it(`Client navigation to same param path with different query params and url params`, () => { | ||
cy.visit(paramPath + `foo/`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{"param":"foo"}`) | ||
cy.window() | ||
.then(win => win.___navigate(paramPath + `foo/` + `?foo=bar`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{"param":"foo"}`) | ||
cy.window() | ||
.then(win => win.___navigate(paramPath + `baz/` + `?foo=bar`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{"param":"baz"}`) | ||
cy.window() | ||
.then(win => win.___navigate(paramPath + `baz/`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{"param":"baz"}`) | ||
}) | ||
}) | ||
|
||
describe.only(`Wildcard path ('${wildcardPath}*')`, () => { | ||
it(`Direct visit no query params`, () => { | ||
cy.visit(wildcardPath + `foo/nested/`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{"wildcard":"foo/nested"}`) | ||
}) | ||
|
||
it(`Direct visit with query params`, () => { | ||
cy.visit(wildcardPath + `foo/nested/` + `?foo=bar`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{"wildcard":"foo/nested"}`) | ||
}) | ||
|
||
it(`Client navigation to same param path with different query params and url params`, () => { | ||
cy.visit(wildcardPath + `foo/`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{"wildcard":"foo"}`) | ||
cy.window() | ||
.then(win => win.___navigate(wildcardPath + `foo/` + `?foo=bar`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{"wildcard":"foo"}`) | ||
cy.window() | ||
.then(win => win.___navigate(wildcardPath + `baz/` + `?foo=bar`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{"wildcard":"baz"}`) | ||
cy.window() | ||
.then(win => win.___navigate(wildcardPath + `baz/`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{"wildcard":"baz"}`) | ||
}) | ||
}) |
22 changes: 22 additions & 0 deletions
22
e2e-tests/development-runtime/src/pages/ssr/param-path/[param].js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react" | ||
|
||
export default function Params({ serverData }) { | ||
return ( | ||
<div> | ||
<h2>Query</h2> | ||
<pre data-testid="query">{JSON.stringify(serverData?.arg?.query)}</pre> | ||
<h2>Params</h2> | ||
<pre data-testid="params">{JSON.stringify(serverData?.arg?.params)}</pre> | ||
<h2>Debug</h2> | ||
<pre>{JSON.stringify({ serverData }, null, 2)}</pre> | ||
</div> | ||
) | ||
} | ||
|
||
export function getServerData(arg) { | ||
return { | ||
props: { | ||
arg, | ||
}, | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
e2e-tests/development-runtime/src/pages/ssr/static-path.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react" | ||
|
||
export default function StaticPath({ serverData }) { | ||
return ( | ||
<div> | ||
<h2>Query</h2> | ||
<pre data-testid="query">{JSON.stringify(serverData?.arg?.query)}</pre> | ||
<h2>Params</h2> | ||
<pre data-testid="params">{JSON.stringify(serverData?.arg?.params)}</pre> | ||
<h2>Debug</h2> | ||
<pre>{JSON.stringify({ serverData }, null, 2)}</pre> | ||
</div> | ||
) | ||
} | ||
|
||
export function getServerData(arg) { | ||
return { | ||
props: { | ||
arg, | ||
}, | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
e2e-tests/development-runtime/src/pages/ssr/wildcard-path/[...wildcard].js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react" | ||
|
||
export default function Wildcard({ serverData }) { | ||
return ( | ||
<div> | ||
<h2>Query</h2> | ||
<pre data-testid="query">{JSON.stringify(serverData?.arg?.query)}</pre> | ||
<h2>Params</h2> | ||
<pre data-testid="params">{JSON.stringify(serverData?.arg?.params)}</pre> | ||
<h2>Debug</h2> | ||
<pre>{JSON.stringify({ serverData }, null, 2)}</pre> | ||
</div> | ||
) | ||
} | ||
|
||
export function getServerData(arg) { | ||
return { | ||
props: { | ||
arg, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
e2e-tests/production-runtime/cypress/integration/ssr.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const staticPath = `/ssr/static-path/` | ||
const paramPath = `/ssr/param-path/` | ||
const wildcardPath = `/ssr/wildcard-path/` | ||
|
||
describe(`Static path ('${staticPath}')`, () => { | ||
it(`Direct visit no query params`, () => { | ||
cy.visit(staticPath).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{}`) | ||
}) | ||
|
||
it(`Direct visit with query params`, () => { | ||
cy.visit(staticPath + `?foo=bar`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{}`) | ||
}) | ||
|
||
it(`Client navigation to same path with different query params`, () => { | ||
cy.visit(staticPath).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{}`) | ||
cy.window() | ||
.then(win => win.___navigate(staticPath + `?foo=bar`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{}`) | ||
cy.window() | ||
.then(win => win.___navigate(staticPath + `?foo=baz`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"baz"}`) | ||
cy.getTestElement(`params`).contains(`{}`) | ||
cy.window() | ||
.then(win => win.___navigate(staticPath)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{}`) | ||
}) | ||
}) | ||
|
||
describe(`Param path ('${paramPath}:param')`, () => { | ||
it(`Direct visit no query params`, () => { | ||
cy.visit(paramPath + `foo/`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{"param":"foo"}`) | ||
}) | ||
|
||
it(`Direct visit with query params`, () => { | ||
cy.visit(paramPath + `foo/` + `?foo=bar`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{"param":"foo"}`) | ||
}) | ||
|
||
it(`Client navigation to same param path with different query params and url params`, () => { | ||
cy.visit(paramPath + `foo/`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{"param":"foo"}`) | ||
cy.window() | ||
.then(win => win.___navigate(paramPath + `foo/` + `?foo=bar`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{"param":"foo"}`) | ||
cy.window() | ||
.then(win => win.___navigate(paramPath + `baz/` + `?foo=bar`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{"param":"baz"}`) | ||
cy.window() | ||
.then(win => win.___navigate(paramPath + `baz/`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{"param":"baz"}`) | ||
}) | ||
}) | ||
|
||
describe.only(`Wildcard path ('${wildcardPath}*')`, () => { | ||
pieh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
it(`Direct visit no query params`, () => { | ||
cy.visit(wildcardPath + `foo/nested/`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{"wildcard":"foo/nested"}`) | ||
}) | ||
|
||
it(`Direct visit with query params`, () => { | ||
cy.visit(wildcardPath + `foo/nested/` + `?foo=bar`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{"wildcard":"foo/nested"}`) | ||
}) | ||
|
||
it(`Client navigation to same param path with different query params and url params`, () => { | ||
cy.visit(wildcardPath + `foo/`).waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{"wildcard":"foo"}`) | ||
cy.window() | ||
.then(win => win.___navigate(wildcardPath + `foo/` + `?foo=bar`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{"wildcard":"foo"}`) | ||
cy.window() | ||
.then(win => win.___navigate(wildcardPath + `baz/` + `?foo=bar`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{"foo":"bar"}`) | ||
cy.getTestElement(`params`).contains(`{"wildcard":"baz"}`) | ||
cy.window() | ||
.then(win => win.___navigate(wildcardPath + `baz/`)) | ||
.waitForRouteChange() | ||
cy.getTestElement(`query`).contains(`{}`) | ||
cy.getTestElement(`params`).contains(`{"wildcard":"baz"}`) | ||
}) | ||
}) |
22 changes: 22 additions & 0 deletions
22
e2e-tests/production-runtime/src/pages/ssr/param-path/[param].js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react" | ||
|
||
export default function Params({ serverData }) { | ||
return ( | ||
<div> | ||
<h2>Query</h2> | ||
<pre data-testid="query">{JSON.stringify(serverData?.arg?.query)}</pre> | ||
<h2>Params</h2> | ||
<pre data-testid="params">{JSON.stringify(serverData?.arg?.params)}</pre> | ||
<h2>Debug</h2> | ||
<pre>{JSON.stringify({ serverData }, null, 2)}</pre> | ||
</div> | ||
) | ||
} | ||
|
||
export function getServerData(arg) { | ||
return { | ||
props: { | ||
arg, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react" | ||
|
||
export default function StaticPath({ serverData }) { | ||
return ( | ||
<div> | ||
<h2>Query</h2> | ||
<pre data-testid="query">{JSON.stringify(serverData?.arg?.query)}</pre> | ||
<h2>Params</h2> | ||
<pre data-testid="params">{JSON.stringify(serverData?.arg?.params)}</pre> | ||
<h2>Debug</h2> | ||
<pre>{JSON.stringify({ serverData }, null, 2)}</pre> | ||
</div> | ||
) | ||
} | ||
|
||
export function getServerData(arg) { | ||
return { | ||
props: { | ||
arg, | ||
}, | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
e2e-tests/production-runtime/src/pages/ssr/wildcard-path/[...wildcard].js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react" | ||
|
||
export default function Wildcard({ serverData }) { | ||
return ( | ||
<div> | ||
<h2>Query</h2> | ||
<pre data-testid="query">{JSON.stringify(serverData?.arg?.query)}</pre> | ||
<h2>Params</h2> | ||
<pre data-testid="params">{JSON.stringify(serverData?.arg?.params)}</pre> | ||
<h2>Debug</h2> | ||
<pre>{JSON.stringify({ serverData }, null, 2)}</pre> | ||
</div> | ||
) | ||
} | ||
|
||
export function getServerData(arg) { | ||
return { | ||
props: { | ||
arg, | ||
}, | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
And same for 2 following changes