Repository: gatsbyjs/gatsby
File: packages/gatsby/src/commands/develop-process.ts (TypeScript)

Code before:
      initializingDataLayer: {
        invoke: {
          src: `initializeDataLayer`,
          data: ({ parentSpan, store }: IBuildContext): IDataLayerContext => {
            return { parentSpan, store, firstRun: true }
          },
          onDone: {
            actions: `assignDataLayer`,
            target: `doingEverythingElse`,
          },
        },
      },
      doingEverythingElse: {
        invoke: {
          src: async ({
            gatsbyNodeGraphQLFunction,
            graphqlRunner,
            workerPool,
            store,
            app,
          }): Promise<void> => {
            // All the stuff that's not in the state machine yet

            // These were previously in `bootstrap()` but are now
            // in part of the state machine that hasn't been added yet
            await postBootstrap({ parentSpan: bootstrapSpan })
            await rebuildSchemaWithSitePage({ parentSpan: bootstrapSpan })

            await extractQueries({ parentSpan: bootstrapSpan })
            await writeOutRedirects({ parentSpan: bootstrapSpan })

            startRedirectListener()
            bootstrapSpan.finish()

            // These are the parts that weren't in bootstrap

            // Start the createPages hot reloader.
            bootstrapPageHotReloader(gatsbyNodeGraphQLFunction)

            // Start the schema hot reloader.
            bootstrapSchemaHotReloader()

            const { queryIds } = await calculateDirtyQueries({ store })

            await runStaticQueries({ queryIds, store, program, graphqlRunner })
            await runPageQueries({ queryIds, store, program, graphqlRunner })
            await writeOutRequires({ store })
            boundActionCreators.setProgramStatus(
              ProgramStatus.BOOTSTRAP_QUERY_RUNNING_FINISHED
            )


Review comment (refactor):
this moves `postBootstrap` before `rebuildSchemaWithSitePage`, `extractQueries`, `writeOutRedirects` - currently we have it like this - https://github.com/gatsbyjs/gatsby/blob/8e4bc927a91c4e73e06eafc69e0673c7ba0553d4/packages/gatsby/src/bootstrap/index.ts#L52-L60

Is this re-order needed for incoming changes? Ideally we don't swap order if we don't have to

Code after:
      initializingDataLayer: {
        invoke: {
          src: `initializeDataLayer`,
          data: ({ parentSpan, store }: IBuildContext): IDataLayerContext => {
            return { parentSpan, store, firstRun: true }
          },
          onDone: {
            actions: `assignDataLayer`,
            target: `doingEverythingElse`,
          },
        },
      },
      doingEverythingElse: {
        invoke: {
          src: async ({
            gatsbyNodeGraphQLFunction,
            graphqlRunner,
            workerPool,
            store,
            app,
          }): Promise<void> => {
            // All the stuff that's not in the state machine yet

            // These were previously in `bootstrap()` but are now
            // in part of the state machine that hasn't been added yet
            await rebuildSchemaWithSitePage({ parentSpan: bootstrapSpan })

            await extractQueries({ parentSpan: bootstrapSpan })
            await writeOutRedirects({ parentSpan: bootstrapSpan })

            startRedirectListener()
            bootstrapSpan.finish()
            await postBootstrap({ parentSpan: bootstrapSpan })

            // These are the parts that weren't in bootstrap

            // Start the createPages hot reloader.
            bootstrapPageHotReloader(gatsbyNodeGraphQLFunction)

            // Start the schema hot reloader.
            bootstrapSchemaHotReloader()

            const { queryIds } = await calculateDirtyQueries({ store })

            await runStaticQueries({ queryIds, store, program, graphqlRunner })
            await runPageQueries({ queryIds, store, program, graphqlRunner })
            await writeOutRequires({ store })
            boundActionCreators.setProgramStatus(
              ProgramStatus.BOOTSTRAP_QUERY_RUNNING_FINISHED
            )