From 70ec220602c414c180e8d4261574c0f7fccfbd9b Mon Sep 17 00:00:00 2001 From: Ravi Chaudhary Date: Thu, 24 Feb 2022 16:44:42 +0100 Subject: [PATCH 1/2] fixed breaking change for gatsby v4 --- package.json | 4 ++-- src/gatsby-browser.js | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 201c44f..49a08d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@wardpeet/gatsby-plugin-static-site", - "version": "0.3.0", + "version": "0.4.0", "description": "A plugin that disables client side routing for gatsby", "main": "index.js", "author": "Ward Peeters ", @@ -17,7 +17,7 @@ }, "license": "MIT", "peerDependencies": { - "gatsby": "^3.0.0" + "gatsby": "^4.0.0" }, "files": [ "gatsby-browser.js", diff --git a/src/gatsby-browser.js b/src/gatsby-browser.js index 5b394eb..9afacd6 100644 --- a/src/gatsby-browser.js +++ b/src/gatsby-browser.js @@ -21,11 +21,14 @@ exports.onClientEntry = () => { loader.loadPageSync = path => { let pageResources; - // if the path is the same as our current page we know it's not a prefetch - if (path === location.pathname) { + // With Gatsby V4, path has been appended with window.location.search when invoking loadPageSync + const pathWithoutQueryParams = path.replace(location.search, ''); + + // if the pathWithoutQueryParams is the same as our current page we know it's not a prefetch + if (pathWithoutQueryParams === location.pathname) { pageResources = originalLoadPageSync(pagePath); } else { - pageResources = originalLoadPageSync(path); + pageResources = originalLoadPageSync(pathWithoutQueryParams); } if (pageResources.page) { @@ -37,11 +40,14 @@ exports.onClientEntry = () => { loader.loadPage = path => { let pageResources; - // if the path is the same as our current page we know it's not a prefetch - if (path === location.pathname) { + // With Gatsby V4, path has been appended with window.location.search when invoking loadPage + const pathWithoutQueryParams = path.replace(location.search, ''); + + // if the pathWithoutQueryParams is the same as our current page we know it's not a prefetch + if (pathWithoutQueryParams === location.pathname) { pageResources = originalLoadPage(pagePath); } else { - pageResources = originalLoadPage(path); + pageResources = originalLoadPage(pathWithoutQueryParams); } if (pageResources.page) { From 3b8b04888b84002d14c7964350def8f0d3695873 Mon Sep 17 00:00:00 2001 From: Ravi Chaudhary Date: Thu, 24 Feb 2022 16:53:39 +0100 Subject: [PATCH 2/2] update peer dep requirement since fix doesn't break anything for Gatsby@V3 compatibility --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 49a08d3..f4fab66 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ }, "license": "MIT", "peerDependencies": { - "gatsby": "^4.0.0" + "gatsby": "^3.0.0 || ^4.0.0" }, "files": [ "gatsby-browser.js",