Skip to content

Commit e56f544

Browse files
authored
perf(gatsby-plugin-page-creator): De-dupe collection pages (#31016)
1 parent 841c0d2 commit e56f544

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/gatsby-plugin-page-creator/src/create-pages-from-collection-builder.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ ${errors.map(error => error.message).join(`\n`)}`.trim(),
105105

106106
let derivePathErrors = 0
107107

108+
const knownPagePaths = new Set<string>()
109+
108110
// 3. Loop through each node and create the page, also save the path it creates to pass to the watcher
109111
// the watcher will use this data to delete the pages if the query changes significantly.
110-
const paths = nodes.map((node: Record<string, Record<string, unknown>>) => {
112+
const paths: Array<string> = []
113+
nodes.forEach((node: Record<string, Record<string, unknown>>) => {
111114
// URL path for the component and node
112115
const { derivedPath, errors } = derivePath(
113116
filePath,
@@ -116,6 +119,11 @@ ${errors.map(error => error.message).join(`\n`)}`.trim(),
116119
slugifyOptions
117120
)
118121
const path = createPath(derivedPath)
122+
// We've already created a page with this path
123+
if (knownPagePaths.has(path)) {
124+
return
125+
}
126+
knownPagePaths.add(path)
119127
// Params is supplied to the FE component on props.params
120128
const params = getCollectionRouteParams(createPath(filePath), path)
121129
// nodeParams is fed to the graphql query for the component
@@ -135,7 +143,7 @@ ${errors.map(error => error.message).join(`\n`)}`.trim(),
135143

136144
derivePathErrors += errors
137145

138-
return path
146+
paths.push(path)
139147
})
140148

141149
if (derivePathErrors > 0) {

0 commit comments

Comments
 (0)