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@3.5.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@3.5.1
Choose a head ref
  • 4 commits
  • 36 files changed
  • 4 contributors

Commits on May 19, 2021

  1. fix(tests): update cheerio snapshots (#31298) (#31483)

    (cherry picked from commit e06599d)
    
    # Conflicts:
    #	packages/gatsby-plugin-offline/package.json
    #	packages/gatsby-remark-images/package.json
    #	packages/gatsby-remark-prismjs/package.json
    
    Co-authored-by: Adam Schay <adamschay@gmail.com>
    vladar and hoobdeebla authored May 19, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    67a4fce View commit details
  2. fix(gatsby): preload and prefetches check for in-browser redirects (#…

    …31366) (#31480)
    
    * fix(gatsby): preload and prefetches check for in-browser redirects
    
    * maybe json and js should not be named the same
    
    * copy json files to commonjs dir
    
    * add e2e test case
    
    * move checking for page and redirect overlap to node from client
    
    * adjust e2e assertions
    
    (cherry picked from commit d86cd9f)
    
    Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
    Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
    3 people authored May 19, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e6e7eec View commit details
  3. fix(gatsby-plugin-mdx): fix gatsby develop on windows (#31396) (#31481)

    (cherry picked from commit ae2e2de)
    
    Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
    Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
    3 people authored May 19, 2021

    Verified

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

     - gatsby-admin@0.15.1
     - gatsby-plugin-mdx@2.5.1
     - gatsby-plugin-offline@4.5.1
     - gatsby-remark-copy-linked-files@4.2.1
     - gatsby-remark-graphviz@3.2.1
     - gatsby-remark-images-contentful@4.2.1
     - gatsby-remark-images@5.2.1
     - gatsby-remark-prismjs@5.2.1
     - gatsby-remark-responsive-iframe@4.2.1
     - gatsby-source-wordpress@5.5.1
     - gatsby@3.5.1
    vladar committed May 19, 2021
    Copy the full SHA
    3f71398 View commit details
Showing with 401 additions and 143 deletions.
  1. +0 −39 e2e-tests/development-runtime/cypress/integration/navigation/redirect.js
  2. +48 −0 e2e-tests/production-runtime/cypress/integration/redirects.js
  3. +15 −0 e2e-tests/production-runtime/src/pages/redirect-links.js
  4. +52 −26 packages/babel-plugin-remove-graphql-queries/src/__tests__/__snapshots__/index.js.snap
  5. +4 −0 packages/gatsby-admin/CHANGELOG.md
  6. +2 −2 packages/gatsby-admin/package.json
  7. +6 −0 packages/gatsby-plugin-mdx/CHANGELOG.md
  8. +3 −4 packages/gatsby-plugin-mdx/loaders/mdx-loader.js
  9. +1 −1 packages/gatsby-plugin-mdx/package.json
  10. +6 −0 packages/gatsby-plugin-offline/CHANGELOG.md
  11. +2 −2 packages/gatsby-plugin-offline/package.json
  12. +6 −0 packages/gatsby-remark-copy-linked-files/CHANGELOG.md
  13. +2 −2 packages/gatsby-remark-copy-linked-files/package.json
  14. +6 −0 packages/gatsby-remark-graphviz/CHANGELOG.md
  15. +2 −2 packages/gatsby-remark-graphviz/package.json
  16. +6 −0 packages/gatsby-remark-images-contentful/CHANGELOG.md
  17. +2 −2 packages/gatsby-remark-images-contentful/package.json
  18. +2 −2 packages/gatsby-remark-images-contentful/src/__tests__/__snapshots__/index.js.snap
  19. +6 −0 packages/gatsby-remark-images/CHANGELOG.md
  20. +2 −2 packages/gatsby-remark-images/package.json
  21. +4 −4 packages/gatsby-remark-images/src/__tests__/__snapshots__/index.js.snap
  22. +6 −0 packages/gatsby-remark-prismjs/CHANGELOG.md
  23. +2 −2 packages/gatsby-remark-prismjs/package.json
  24. +6 −0 packages/gatsby-remark-responsive-iframe/CHANGELOG.md
  25. +2 −2 packages/gatsby-remark-responsive-iframe/package.json
  26. +6 −0 packages/gatsby-source-wordpress/CHANGELOG.md
  27. +2 −2 packages/gatsby-source-wordpress/package.json
  28. +7 −0 packages/gatsby/CHANGELOG.md
  29. +6 −0 packages/gatsby/cache-dir/find-path.js
  30. +4 −31 packages/gatsby/cache-dir/navigation.js
  31. +22 −0 packages/gatsby/cache-dir/redirect-utils.js
  32. +2 −2 packages/gatsby/package.json
  33. +1 −1 packages/gatsby/src/bootstrap/__tests__/__snapshots__/resolve-module-exports.js.snap
  34. +116 −0 packages/gatsby/src/bootstrap/__tests__/redirects-writer.ts
  35. +41 −14 packages/gatsby/src/bootstrap/redirects-writer.ts
  36. +1 −1 yarn.lock
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
let spy
Cypress.on(`window:before:load`, win => {
spy = cy.spy(win.console, `error`).as(`spyWinConsoleError`)
})

const runTests = () => {
it(`should redirect page to index page when there is no such page`, () => {
cy.visit(`/redirect-without-page`, {
failOnStatusCode: false,
}).waitForRouteChange()

cy.location(`pathname`).should(`equal`, `/`)
cy.then(() => {
const calls = spy.getCalls()

const callsAboutRedirectMatchingPage = calls.filter(call =>
call.args[0].includes(
`matches both a page and a redirect; this is probably not intentional.`
)
)

expect(callsAboutRedirectMatchingPage.length).to.equal(0)
})
})

it(`should redirect page to index page even there is a such page`, () => {
@@ -29,20 +13,6 @@ const runTests = () => {
}).waitForRouteChange()

cy.location(`pathname`).should(`equal`, `/`)
cy.then(() => {
const calls = spy.getCalls()

const callsAboutRedirectMatchingPage = calls.filter(call =>
call.args[0].includes(
`matches both a page and a redirect; this is probably not intentional.`
)
)

expect(callsAboutRedirectMatchingPage.length).not.to.equal(0)
expect(spy).to.be.calledWith(
`The route "/redirect" matches both a page and a redirect; this is probably not intentional.`
)
})
})

it(`should redirect to a dynamically-created replacement page`, () => {
@@ -51,15 +21,6 @@ const runTests = () => {
}).waitForRouteChange()

cy.location(`pathname`).should(`equal`, `/pt/redirect-me/`)
cy.then(() => {
expect(spy).not.to.be.calledWith(
`The route "/redirect" matches both a page and a redirect; this is probably not intentional.`
)

cy.findByText(`This should be at /pt/redirect-me/`, {
exact: false,
}).should(`exist`)
})
})
}

48 changes: 48 additions & 0 deletions e2e-tests/production-runtime/cypress/integration/redirects.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
let spy
Cypress.on(`window:before:load`, win => {
spy = cy.spy(win.console, `error`).as(`spyWinConsoleError`)
})

describe(`Redirects`, () => {
it(`are case insensitive when ignoreCase is set to true`, () => {
cy.visit(`/Longue-PAGE`, { failOnStatusCode: false }).waitForRouteChange()
@@ -9,4 +14,47 @@ describe(`Redirects`, () => {

cy.get(`h1`).invoke(`text`).should(`contain`, `NOT FOUND`)
})

it(`use redirects when preloading page-data`, () => {
const expectedLinks = [`/Longue-PAGE`, `/pagina-larga`]

// we should not hit those routes
cy.intercept("GET", "/page-data/Longue-PAGE/page-data.json").as(
"page-data-for-redirected-page-a"
)
cy.intercept("GET", "/page-data/pagina-larga/page-data.json").as(
"page-data-for-redirected-page-b"
)

cy.intercept("GET", "/page-data/long-page/page-data.json").as(
"redirected-page-data"
)

cy.visit(`/redirect-links/`).waitForRouteChange()

cy.get("a").each(($el, index, $list) => {
cy.then(() => {
expect($el[0].href.replace(`http://localhost:9000`, ``)).to.be.oneOf(
expectedLinks
)
})
// focus / hover links to force trigger preload
cy.wrap($el).trigger("mouseover")
})

cy.then(() => {
// those requests should not happen
cy.get("@page-data-for-redirected-page-a").should(networkCall => {
expect(networkCall).to.be.null
})
cy.get("@page-data-for-redirected-page-b").should(networkCall => {
expect(networkCall).to.be.null
})

// instead we want links to use redirects
cy.get("@redirected-page-data").should(networkCall => {
expect(networkCall.response.statusCode).to.be.oneOf([304, 200])
})
})
})
})
15 changes: 15 additions & 0 deletions e2e-tests/production-runtime/src/pages/redirect-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from "react"
import { Link } from "gatsby"

export default function RedirectLinks() {
return (
<ul>
<li>
<Link to="/Longue-PAGE">/Longue-PAGE</Link>
</li>
<li>
<Link to="/pagina-larga">/pagina-larga</Link>
</li>
</ul>
)
}
Loading