Skip to content

Commit

Permalink
fix(gatsby): single page node manifest accuracy (#33642)
Browse files Browse the repository at this point in the history
* expect the manifest has the correct foundPageBy
* ensure foundPageBy is accurate when there's only 1 relevant page
  • Loading branch information
TylerBarnes authored and axe312ger committed Nov 9, 2021
1 parent 02ae524 commit 6bc4acd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ 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 () => {
const manifestFileContents = await getManifestContents(2)

expect(manifestFileContents.node.id).toBe(`2`)
expect(manifestFileContents.page.path).toBe(`/two`)
expect(manifestFileContents.foundPageBy).toBe(`context.id`)
})

if (gatsbyCommandName === `build`) {
Expand All @@ -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
Expand All @@ -93,12 +96,14 @@ 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 () => {
const manifestFileContents = await getManifestContents(`filesystem-1`)

expect(manifestFileContents.node.id).toBe(`filesystem-1`)
expect(manifestFileContents.page.path).toBe(`/filesystem-1/`)
expect(manifestFileContents.foundPageBy).toBe(`filesystem-route-api`)
})
})
4 changes: 1 addition & 3 deletions packages/gatsby/src/utils/node-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6bc4acd

Please sign in to comment.