diff --git a/packages/gatsby/src/internal-plugins/query-runner/pages-writer.js b/packages/gatsby/src/internal-plugins/query-runner/pages-writer.js index 86ef1079d23d4..fb698e963ada9 100644 --- a/packages/gatsby/src/internal-plugins/query-runner/pages-writer.js +++ b/packages/gatsby/src/internal-plugins/query-runner/pages-writer.js @@ -152,6 +152,18 @@ const debouncedWritePages = _.debounce( 500, { leading: true } ) +emitter.on(`CREATE_PAGE`, () => { + // Ignore CREATE_PAGE until bootstrap is finished + // as this is called many many times during bootstrap and + // we can ignore them until CREATE_PAGE_END is called. + // + // After bootstrap, we need to listen for this as stateful page + // creators e.g. the internal plugin "component-page-creator" + // calls createPage directly so CREATE_PAGE_END won't get fired. + if (bootstrapFinished) { + debouncedWritePages() + } +}) emitter.on(`CREATE_PAGE_END`, () => { debouncedWritePages()