Skip to content

Commit

Permalink
perf(gatsby-plugin-page-creator): De-dupe collection pages (#31016)
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Apr 23, 2021
1 parent 841c0d2 commit e56f544
Showing 1 changed file with 10 additions and 2 deletions.
Expand Up @@ -105,9 +105,12 @@ ${errors.map(error => error.message).join(`\n`)}`.trim(),

let derivePathErrors = 0

const knownPagePaths = new Set<string>()

// 3. Loop through each node and create the page, also save the path it creates to pass to the watcher
// the watcher will use this data to delete the pages if the query changes significantly.
const paths = nodes.map((node: Record<string, Record<string, unknown>>) => {
const paths: Array<string> = []
nodes.forEach((node: Record<string, Record<string, unknown>>) => {
// URL path for the component and node
const { derivedPath, errors } = derivePath(
filePath,
Expand All @@ -116,6 +119,11 @@ ${errors.map(error => error.message).join(`\n`)}`.trim(),
slugifyOptions
)
const path = createPath(derivedPath)
// We've already created a page with this path
if (knownPagePaths.has(path)) {
return
}
knownPagePaths.add(path)
// Params is supplied to the FE component on props.params
const params = getCollectionRouteParams(createPath(filePath), path)
// nodeParams is fed to the graphql query for the component
Expand All @@ -135,7 +143,7 @@ ${errors.map(error => error.message).join(`\n`)}`.trim(),

derivePathErrors += errors

return path
paths.push(path)
})

if (derivePathErrors > 0) {
Expand Down

0 comments on commit e56f544

Please sign in to comment.