From 4b6d04b9b8b9c68d651a78f1cb42a18eca846fa5 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Mon, 25 Oct 2021 09:02:44 -0700 Subject: [PATCH] fix(gatsby): single page node manifest accuracy (#33642) * expect the manifest has the correct foundPageBy * ensure foundPageBy is accurate when there's only 1 relevant page --- .../node-manifest/__tests__/create-node-manifest.test.js | 5 +++++ packages/gatsby/src/utils/node-manifest.ts | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/integration-tests/node-manifest/__tests__/create-node-manifest.test.js b/integration-tests/node-manifest/__tests__/create-node-manifest.test.js index ae2af3f1aadea..6a6f65bddd16f 100644 --- a/integration-tests/node-manifest/__tests__/create-node-manifest.test.js +++ b/integration-tests/node-manifest/__tests__/create-node-manifest.test.js @@ -53,6 +53,7 @@ describe(`Node Manifest API in "gatsby ${gatsbyCommandName}"`, () => { expect(manifestFileContents.node.id).toBe(`1`) expect(manifestFileContents.page.path).toBe(`/one`) + expect(manifestFileContents.foundPageBy).toBe(`ownerNodeId`) }) it(`Creates an accurate node manifest when ownerNodeId isn't present but there's a matching "id" in pageContext`, async () => { @@ -60,6 +61,7 @@ describe(`Node Manifest API in "gatsby ${gatsbyCommandName}"`, () => { expect(manifestFileContents.node.id).toBe(`2`) expect(manifestFileContents.page.path).toBe(`/two`) + expect(manifestFileContents.foundPageBy).toBe(`context.id`) }) if (gatsbyCommandName === `build`) { @@ -74,6 +76,7 @@ describe(`Node Manifest API in "gatsby ${gatsbyCommandName}"`, () => { manifestFileContents.page.path ) ).toBe(true) + expect(manifestFileContents.foundPageBy).toBe(`queryTracking`) }) // this doesn't work in gatsby develop since page-data.json files aren't written out @@ -93,6 +96,7 @@ describe(`Node Manifest API in "gatsby ${gatsbyCommandName}"`, () => { expect(manifestFileContents.node.id).toBe(`4`) expect(manifestFileContents.page.path).toBe(null) + expect(manifestFileContents.foundPageBy).toBe(`none`) }) it(`Creates a Node manifest for filesystem routes`, async () => { @@ -100,5 +104,6 @@ describe(`Node Manifest API in "gatsby ${gatsbyCommandName}"`, () => { expect(manifestFileContents.node.id).toBe(`filesystem-1`) expect(manifestFileContents.page.path).toBe(`/filesystem-1/`) + expect(manifestFileContents.foundPageBy).toBe(`filesystem-route-api`) }) }) diff --git a/packages/gatsby/src/utils/node-manifest.ts b/packages/gatsby/src/utils/node-manifest.ts index 077b355a49bff..9f6290e941715 100644 --- a/packages/gatsby/src/utils/node-manifest.ts +++ b/packages/gatsby/src/utils/node-manifest.ts @@ -70,9 +70,7 @@ async function findPageOwnedByNodeId({ nodeId }: { nodeId: string }): Promise<{ let foundPageBy: FoundPageBy = pagePath ? `queryTracking` : `none` - // but if we have more than one page where this node shows up - // we need to try to be more specific - if (pagePathSetOrMap && pagePathSetOrMap.size > 1) { + if (pagePathSetOrMap) { let ownerPagePath: string | undefined let foundOwnerNodeId = false