From d9a5ff0ce28f3c80a09fe1e281be4409cb37f043 Mon Sep 17 00:00:00 2001 From: Rob Stanford Date: Thu, 21 Apr 2022 17:26:03 +0100 Subject: [PATCH 1/3] fix: ignore named splats when writing redirects --- src/gatsby-node.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gatsby-node.ts b/src/gatsby-node.ts index 121cdf28..fad10632 100644 --- a/src/gatsby-node.ts +++ b/src/gatsby-node.ts @@ -78,7 +78,7 @@ export const onPostBuild = async ({ store, pathPrefix, reporter }: any, userPlug const { mode, matchPath, path } = page if (mode === `SSR` || mode === `DSG`) { needsFunctions = true - const fromPath = matchPath ?? path + const fromPath = matchPath.replace(/\*.*/, '*') ?? path const toPath = mode === `SSR` ? `/.netlify/functions/__ssr` : `/.netlify/functions/__dsg` count++ rewrites.push( @@ -94,7 +94,7 @@ export const onPostBuild = async ({ store, pathPrefix, reporter }: any, userPlug } if (pluginOptions.generateMatchPathRewrites && matchPath && matchPath !== path) { rewrites.push({ - fromPath: matchPath, + fromPath: matchPath.replace(/\*.*/, '*'), toPath: path, }) } From 5bc3e3123b6232e9657e78825383fca6e3181857 Mon Sep 17 00:00:00 2001 From: Rob Stanford Date: Thu, 21 Apr 2022 17:26:15 +0100 Subject: [PATCH 2/3] fix: make ssr/dsg and client-only redirects mutually exclusive --- src/gatsby-node.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gatsby-node.ts b/src/gatsby-node.ts index fad10632..a9c31cf2 100644 --- a/src/gatsby-node.ts +++ b/src/gatsby-node.ts @@ -91,8 +91,7 @@ export const onPostBuild = async ({ store, pathPrefix, reporter }: any, userPlug toPath, }, ) - } - if (pluginOptions.generateMatchPathRewrites && matchPath && matchPath !== path) { + } else if (pluginOptions.generateMatchPathRewrites && matchPath && matchPath !== path) { rewrites.push({ fromPath: matchPath.replace(/\*.*/, '*'), toPath: path, From 13cac4fd157a2ff5ff1201b54ced01d61fff6b2a Mon Sep 17 00:00:00 2001 From: Rob Stanford Date: Thu, 21 Apr 2022 18:04:52 +0100 Subject: [PATCH 3/3] fix: handle undefined matchpath --- src/gatsby-node.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gatsby-node.ts b/src/gatsby-node.ts index a9c31cf2..00f87a53 100644 --- a/src/gatsby-node.ts +++ b/src/gatsby-node.ts @@ -76,9 +76,12 @@ export const onPostBuild = async ({ store, pathPrefix, reporter }: any, userPlug ;[...pages.values()].forEach((page) => { const { mode, matchPath, path } = page + const matchPathClean = matchPath && matchPath.replace(/\*.*/, '*') + const matchPathIsNotPath = matchPath && matchPath !== path + if (mode === `SSR` || mode === `DSG`) { needsFunctions = true - const fromPath = matchPath.replace(/\*.*/, '*') ?? path + const fromPath = matchPathClean ?? path const toPath = mode === `SSR` ? `/.netlify/functions/__ssr` : `/.netlify/functions/__dsg` count++ rewrites.push( @@ -91,9 +94,9 @@ export const onPostBuild = async ({ store, pathPrefix, reporter }: any, userPlug toPath, }, ) - } else if (pluginOptions.generateMatchPathRewrites && matchPath && matchPath !== path) { + } else if (pluginOptions.generateMatchPathRewrites && matchPathIsNotPath) { rewrites.push({ - fromPath: matchPath.replace(/\*.*/, '*'), + fromPath: matchPathClean, toPath: path, }) }