Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gatsbyjs/gatsby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: gatsby@4.1.0
Choose a base ref
...
head repository: gatsbyjs/gatsby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: gatsby@4.1.1
Choose a head ref
  • 3 commits
  • 7 files changed
  • 4 contributors

Commits on Nov 8, 2021

  1. fix(gatsby): preserve query params on pages without trailing slashes (#…

    …33811) (#33894)
    
    Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
    GatsbyJS Bot and pieh authored Nov 8, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e32b355 View commit details
  2. searcParams missing from urls (#33861) (#33895)

    Co-authored-by: Joe Stramel <jstramel@users.noreply.github.com>
    GatsbyJS Bot and jstramel authored Nov 8, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    60de482 View commit details
  3. chore(release): Publish

     - gatsby-source-drupal@5.1.1
     - gatsby@4.1.1
    LekoArts committed Nov 8, 2021
    Copy the full SHA
    95a3524 View commit details
50 changes: 50 additions & 0 deletions e2e-tests/production-runtime/cypress/integration/1-production.js
Original file line number Diff line number Diff line change
@@ -207,4 +207,54 @@ describe(`Production build tests`, () => {
cy.getTestElement(`404`).should(`exist`)
})
})

describe(`Keeps search query`, () => {
describe(`No trailing slash canonical path (/slashes/no-trailing)`, () => {
it(`/slashes/no-trailing?param=value`, () => {
cy.visit(`/slashes/no-trailing?param=value`).waitForRouteChange()

cy.getTestElement(`search-marker`)
.invoke(`text`)
.should(`equal`, `?param=value`)

cy.location(`pathname`).should(`equal`, `/slashes/no-trailing`)
cy.location(`search`).should(`equal`, `?param=value`)
})

it(`/slashes/no-trailing/?param=value`, () => {
cy.visit(`/slashes/no-trailing/?param=value`).waitForRouteChange()

cy.getTestElement(`search-marker`)
.invoke(`text`)
.should(`equal`, `?param=value`)

cy.location(`pathname`).should(`equal`, `/slashes/no-trailing`)
cy.location(`search`).should(`equal`, `?param=value`)
})
})

describe(`With trailing slash canonical path (/slashes/with-trailing/)`, () => {
it(`/slashes/with-trailing?param=value`, () => {
cy.visit(`/slashes/with-trailing?param=value`).waitForRouteChange()

cy.getTestElement(`search-marker`)
.invoke(`text`)
.should(`equal`, `?param=value`)

cy.location(`pathname`).should(`equal`, `/slashes/with-trailing/`)
cy.location(`search`).should(`equal`, `?param=value`)
})

it(`/slashes/with-trailing/?param=value`, () => {
cy.visit(`/slashes/with-trailing/?param=value`).waitForRouteChange()

cy.getTestElement(`search-marker`)
.invoke(`text`)
.should(`equal`, `?param=value`)

cy.location(`pathname`).should(`equal`, `/slashes/with-trailing/`)
cy.location(`search`).should(`equal`, `?param=value`)
})
})
})
})
16 changes: 16 additions & 0 deletions e2e-tests/production-runtime/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -130,6 +130,22 @@ exports.createPages = ({ actions: { createPage, createRedirect } }) => {
component: path.resolve(`./.cache/static-page-from-cache.js`),
})

{
const searchParamComponent = path.resolve(
`src/templates/search-param-render.js`
)

createPage({
path: `/slashes/no-trailing`,
component: searchParamComponent,
})

createPage({
path: `/slashes/with-trailing/`,
component: searchParamComponent,
})
}

createRedirect({
fromPath: "/pagina-larga",
toPath: "/long-page",
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from "react"

const SearchParam = ({ location }) => (
<pre data-testid="search-marker">{location.search}</pre>
)

export default SearchParam
2 changes: 1 addition & 1 deletion packages/gatsby-source-drupal/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-source-drupal",
"description": "Gatsby source plugin for building websites using the Drupal CMS as a data source",
"version": "5.1.0",
"version": "5.1.1",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
16 changes: 16 additions & 0 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -61,6 +61,21 @@ async function worker([url, options]) {
}
}

if (typeof options.searchParams === `object`) {
url = new URL(url)
const searchParams = new URLSearchParams(options.searchParams)
const searchKeys = Array.from(searchParams.keys())
searchKeys.forEach(searchKey => {
// Only add search params to url if it has not already been
// added.
if (!url.searchParams.has(searchKey)) {
url.searchParams.set(searchKey, searchParams.get(searchKey))
}
})
url = url.toString()
}
delete options.searchParams

const response = await got(url, {
agent,
cache: false,
@@ -467,6 +482,7 @@ ${JSON.stringify(webhookBody, null, 4)}`
username: basicAuth.username,
password: basicAuth.password,
headers,
searchParams: params,
responseType: `json`,
parentSpan: fullFetchSpan,
},
12 changes: 9 additions & 3 deletions packages/gatsby/cache-dir/production-app.js
Original file line number Diff line number Diff line change
@@ -149,9 +149,15 @@ apiRunnerAsync(`onClientEntry`).then(() => {
pagePath.match(/^\/offline-plugin-app-shell-fallback\/?$/)
)
) {
navigate(__BASE_PATH__ + pagePath + browserLoc.hash, {
replace: true,
})
navigate(
__BASE_PATH__ +
pagePath +
(!pagePath.includes(`?`) ? browserLoc.search : ``) +
browserLoc.hash,
{
replace: true,
}
)
}

publicLoader.loadPage(browserLoc.pathname + browserLoc.search).then(page => {
2 changes: 1 addition & 1 deletion packages/gatsby/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby",
"description": "Blazing fast modern site generator for React",
"version": "4.1.0",
"version": "4.1.1",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"bin": {
"gatsby": "./cli.js"