diff --git a/packages/gatsby/src/bootstrap/__tests__/requires-writer.js b/packages/gatsby/src/bootstrap/__tests__/requires-writer.js index 5506421f45541..b82fa698dc0e6 100644 --- a/packages/gatsby/src/bootstrap/__tests__/requires-writer.js +++ b/packages/gatsby/src/bootstrap/__tests__/requires-writer.js @@ -326,4 +326,29 @@ describe(`requires-writer`, () => { }) }) }) + + describe(`getComponents`, () => { + it(`should return components in a deterministic order`, () => { + const pagesInput = generatePagesState([ + { + component: `component1`, + componentChunkName: `chunkName1`, + matchPath: `matchPath1`, + path: `/path1`, + }, + { + component: `component2`, + componentChunkName: `chunkName2`, + path: `/path2`, + }, + ]) + + const pages = [...pagesInput.values()] + const pagesReversed = [...pagesInput.values()].reverse() + + expect(requiresWriter.getComponents(pages)).toEqual( + requiresWriter.getComponents(pagesReversed) + ) + }) + }) }) diff --git a/packages/gatsby/src/bootstrap/requires-writer.js b/packages/gatsby/src/bootstrap/requires-writer.js index f1c24b6061791..e34c0c72a948e 100644 --- a/packages/gatsby/src/bootstrap/requires-writer.js +++ b/packages/gatsby/src/bootstrap/requires-writer.js @@ -52,6 +52,7 @@ const getComponents = pages => _(pages) .map(pickComponentFields) .uniqBy(c => c.componentChunkName) + .orderBy(c => c.componentChunkName) .value() /** @@ -254,4 +255,5 @@ module.exports = { writeAll, resetLastHash, startListener, + getComponents, }