From ba9ba100c35749b371e875e532e28db9ebbe0e87 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Mon, 13 Jul 2020 10:20:30 +0100 Subject: [PATCH 1/4] Move remaining parts into state machine --- .../gatsby/src/commands/develop-process.ts | 58 ++----------------- .../src/services/write-out-redirects.ts | 6 +- packages/gatsby/src/state-machines/actions.ts | 4 ++ .../src/state-machines/data-layer/index.ts | 34 +++++++++-- .../state-machines/query-running/actions.ts | 13 +++++ .../src/state-machines/query-running/index.ts | 14 +++++ 6 files changed, 72 insertions(+), 57 deletions(-) diff --git a/packages/gatsby/src/commands/develop-process.ts b/packages/gatsby/src/commands/develop-process.ts index a0d008ac8caf6..e765d8145244e 100644 --- a/packages/gatsby/src/commands/develop-process.ts +++ b/packages/gatsby/src/commands/develop-process.ts @@ -4,26 +4,16 @@ import chalk from "chalk" import telemetry from "gatsby-telemetry" import express from "express" import { initTracer } from "../utils/tracer" -import db from "../db" import { detectPortInUseAndPrompt } from "../utils/detect-port-in-use-and-prompt" import onExit from "signal-exit" import { userPassesFeedbackRequestHeuristic, showFeedbackRequest, } from "../utils/feedback" -import { startRedirectListener } from "../bootstrap/redirects-writer" import { markWebpackStatusAsPending } from "../utils/webpack-status" import { IProgram } from "./types" -import { - IBuildContext, - initialize, - rebuildSchemaWithSitePage, - writeOutRedirects, - startWebpackServer, -} from "../services" -import { boundActionCreators } from "../redux/actions" -import { ProgramStatus } from "../redux/types" +import { IBuildContext, initialize, startWebpackServer } from "../services" import { MachineConfig, AnyEventObject, @@ -168,33 +158,15 @@ module.exports = async (program: IProgram): Promise => { } }, onDone: { - actions: [`assignServiceResult`, `clearWebhookBody`], + actions: [ + `assignServiceResult`, + `clearWebhookBody`, + `finishParentSpan`, + ], target: `finishingBootstrap`, }, }, }, - finishingBootstrap: { - on: { - ADD_NODE_MUTATION: runMutationAndMarkDirty, - // Ignore, because we're about to extract them anyway - QUERY_FILE_CHANGED: undefined, - }, - invoke: { - src: async (): Promise => { - // 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 writeOutRedirects({ parentSpan: bootstrapSpan }) - - startRedirectListener() - bootstrapSpan.finish() - }, - onDone: { - target: `runningQueries`, - }, - }, - }, runningQueries: { on: { QUERY_FILE_CHANGED: { @@ -223,24 +195,6 @@ module.exports = async (program: IProgram): Promise => { websocketManager, } }, - onDone: { - target: `doingEverythingElse`, - }, - }, - }, - doingEverythingElse: { - invoke: { - src: async (): Promise => { - // All the stuff that's not in the state machine yet - - boundActionCreators.setProgramStatus( - ProgramStatus.BOOTSTRAP_QUERY_RUNNING_FINISHED - ) - - await db.saveState() - - db.startAutosave() - }, onDone: [ { target: `startingDevServers`, diff --git a/packages/gatsby/src/services/write-out-redirects.ts b/packages/gatsby/src/services/write-out-redirects.ts index 5745db6dc6fdf..18822eb781ff3 100644 --- a/packages/gatsby/src/services/write-out-redirects.ts +++ b/packages/gatsby/src/services/write-out-redirects.ts @@ -1,5 +1,8 @@ import reporter from "gatsby-cli/lib/reporter" -import { writeRedirects } from "../bootstrap/redirects-writer" +import { + writeRedirects, + startRedirectListener, +} from "../bootstrap/redirects-writer" import { IQueryRunningContext } from "../state-machines/query-running/types" export async function writeOutRedirects({ @@ -11,5 +14,6 @@ export async function writeOutRedirects({ }) activity.start() await writeRedirects() + startRedirectListener() activity.end() } diff --git a/packages/gatsby/src/state-machines/actions.ts b/packages/gatsby/src/state-machines/actions.ts index 4accf988745f8..114693dac9ed6 100644 --- a/packages/gatsby/src/state-machines/actions.ts +++ b/packages/gatsby/src/state-machines/actions.ts @@ -83,6 +83,9 @@ export const clearWebhookBody = assign({ webhookBody: undefined, }) +export const finishParentSpan = ({ parentSpan }: IBuildContext): void => + parentSpan?.finish() + /** * Event handler used in all states where we're not ready to process a file change * Instead we add it to a batch to process when we're next idle @@ -106,4 +109,5 @@ export const buildActions: ActionFunctionMap = { markQueryFilesDirty, assignWebhookBody, clearWebhookBody, + finishBootstrapSpan: finishParentSpan, } diff --git a/packages/gatsby/src/state-machines/data-layer/index.ts b/packages/gatsby/src/state-machines/data-layer/index.ts index 56f5de475c4f6..ef9a3171f2c9a 100644 --- a/packages/gatsby/src/state-machines/data-layer/index.ts +++ b/packages/gatsby/src/state-machines/data-layer/index.ts @@ -19,8 +19,7 @@ const dataLayerStates: MachineConfig = { always: [ { target: `buildingSchema`, - cond: ({ skipSourcing }: IDataLayerContext): boolean => - !!skipSourcing, + cond: `shouldSkipSourcing`, }, { target: `customizingSchema`, @@ -65,10 +64,10 @@ const dataLayerStates: MachineConfig = { { target: `creatingPagesStatefully`, actions: `assignChangedPages`, - cond: (context): boolean => !!context.firstRun, + cond: `firstRun`, }, { - target: `done`, + target: `rebuildingSchemaWithSitePage`, actions: `assignChangedPages`, }, ], @@ -78,6 +77,28 @@ const dataLayerStates: MachineConfig = { invoke: { src: `createPagesStatefully`, id: `creating-pages-statefully`, + onDone: { + target: `rebuildingSchemaWithSitePage`, + }, + }, + }, + rebuildingSchemaWithSitePage: { + invoke: { + src: `rebuildSchemaWithSitePage`, + onDone: [ + { + target: `writingOutRedirects`, + cond: `firstRun`, + }, + { + target: `done`, + }, + ], + }, + }, + writingOutRedirects: { + invoke: { + src: `writeOutRedirects`, onDone: { target: `done`, }, @@ -105,4 +126,9 @@ const dataLayerStates: MachineConfig = { export const dataLayerMachine = Machine(dataLayerStates, { actions: dataLayerActions, services: dataLayerServices, + guards: { + firstRun: ({ firstRun }: IDataLayerContext): boolean => !!firstRun, + shouldSkipSourcing: ({ skipSourcing }: IDataLayerContext): boolean => + !!skipSourcing, + }, }) diff --git a/packages/gatsby/src/state-machines/query-running/actions.ts b/packages/gatsby/src/state-machines/query-running/actions.ts index 93d3ebfae03f7..f717305b169ea 100644 --- a/packages/gatsby/src/state-machines/query-running/actions.ts +++ b/packages/gatsby/src/state-machines/query-running/actions.ts @@ -3,6 +3,9 @@ import { DoneInvokeEvent, assign, ActionFunctionMap } from "xstate" import { GraphQLRunner } from "../../query/graphql-runner" import { assertStore } from "../../utils/assert-store" import { enqueueFlush } from "../../utils/page-data" +import { boundActionCreators } from "../../redux/actions" +import { ProgramStatus } from "../../redux/types" +import db from "../../db" export const flushPageData = (): void => { enqueueFlush() @@ -36,6 +39,15 @@ export const resetGraphQLRunner = assign< }, }) +const finishUpQueries = async (): Promise => { + boundActionCreators.setProgramStatus( + ProgramStatus.BOOTSTRAP_QUERY_RUNNING_FINISHED + ) + await db.saveState() + + db.startAutosave() +} + export const queryActions: ActionFunctionMap< IQueryRunningContext, DoneInvokeEvent @@ -44,4 +56,5 @@ export const queryActions: ActionFunctionMap< assignDirtyQueries, flushPageData, markFilesClean, + finishUpQueries, } diff --git a/packages/gatsby/src/state-machines/query-running/index.ts b/packages/gatsby/src/state-machines/query-running/index.ts index a4aea1ea1f6a2..63290140827fa 100644 --- a/packages/gatsby/src/state-machines/query-running/index.ts +++ b/packages/gatsby/src/state-machines/query-running/index.ts @@ -75,6 +75,20 @@ export const queryStates: MachineConfig = { }, }, }, + finishingUp: { + on: { + always: [ + { + target: `done`, + actions: `finishUpQueries`, + cond: ({ firstRun }): boolean => !!firstRun, + }, + { + target: `done`, + }, + ], + }, + }, done: { type: `final`, }, From b497646bffa3c763ff0c29f63396da252fe5b539 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Mon, 13 Jul 2020 10:33:59 +0100 Subject: [PATCH 2/4] Move top level state machine into state machines dir --- .../gatsby/src/commands/develop-process.ts | 194 +----------------- .../src/state-machines/data-layer/actions.ts | 2 +- .../state-machines/{ => develop}/actions.ts | 10 +- .../src/state-machines/develop/index.ts | 170 +++++++++++++++ .../src/state-machines/develop/services.ts | 13 ++ 5 files changed, 199 insertions(+), 190 deletions(-) rename packages/gatsby/src/state-machines/{ => develop}/actions.ts (90%) create mode 100644 packages/gatsby/src/state-machines/develop/index.ts create mode 100644 packages/gatsby/src/state-machines/develop/services.ts diff --git a/packages/gatsby/src/commands/develop-process.ts b/packages/gatsby/src/commands/develop-process.ts index e765d8145244e..379620f392d91 100644 --- a/packages/gatsby/src/commands/develop-process.ts +++ b/packages/gatsby/src/commands/develop-process.ts @@ -13,26 +13,10 @@ import { import { markWebpackStatusAsPending } from "../utils/webpack-status" import { IProgram } from "./types" -import { IBuildContext, initialize, startWebpackServer } from "../services" -import { - MachineConfig, - AnyEventObject, - Machine, - interpret, - Actor, - Interpreter, - forwardTo, - State, -} from "xstate" -import { dataLayerMachine } from "../state-machines/data-layer" -import { IDataLayerContext } from "../state-machines/data-layer/types" +import { IBuildContext } from "../services" +import { AnyEventObject, interpret, Actor, Interpreter, State } from "xstate" import { globalTracer } from "opentracing" -import { IQueryRunningContext } from "../state-machines/query-running/types" -import { queryRunningMachine } from "../state-machines/query-running" -import { IWaitingContext } from "../state-machines/waiting/types" -import { runMutationAndMarkDirty } from "../state-machines/shared-transition-configs" -import { buildActions } from "../state-machines/actions" -import { waitingMachine } from "../state-machines/waiting" +import { developMachine } from "../state-machines/develop" const tracer = globalTracer() @@ -71,7 +55,6 @@ process.on(`message`, msg => { module.exports = async (program: IProgram): Promise => { reporter.setVerbose(program.verbose) - const bootstrapSpan = tracer.startSpan(`bootstrap`) // We want to prompt the feedback request when users quit develop // assuming they pass the heuristic check to know they are a user @@ -115,171 +98,14 @@ module.exports = async (program: IProgram): Promise => { } const app = express() + const parentSpan = tracer.startSpan(`bootstrap`) - const developConfig: MachineConfig = { - id: `build`, - initial: `initializing`, - states: { - initializing: { - on: { - // Ignore mutation events because we'll be running everything anyway - ADD_NODE_MUTATION: undefined, - QUERY_FILE_CHANGED: undefined, - WEBHOOK_RECEIVED: undefined, - }, - invoke: { - src: `initialize`, - onDone: { - target: `initializingDataLayer`, - actions: [`assignStoreAndWorkerPool`, `spawnMutationListener`], - }, - }, - }, - initializingDataLayer: { - on: { - ADD_NODE_MUTATION: runMutationAndMarkDirty, - // Ignore, because we're about to extract them anyway - QUERY_FILE_CHANGED: undefined, - }, - invoke: { - src: `initializeDataLayer`, - data: ({ - parentSpan, - store, - firstRun, - webhookBody, - }: IBuildContext): IDataLayerContext => { - return { - parentSpan, - store, - firstRun, - deferNodeMutation: true, - webhookBody, - } - }, - onDone: { - actions: [ - `assignServiceResult`, - `clearWebhookBody`, - `finishParentSpan`, - ], - target: `finishingBootstrap`, - }, - }, - }, - runningQueries: { - on: { - QUERY_FILE_CHANGED: { - actions: forwardTo(`run-queries`), - }, - }, - invoke: { - id: `run-queries`, - src: `runQueries`, - data: ({ - program, - store, - parentSpan, - gatsbyNodeGraphQLFunction, - graphqlRunner, - websocketManager, - firstRun, - }: IBuildContext): IQueryRunningContext => { - return { - firstRun, - program, - store, - parentSpan, - gatsbyNodeGraphQLFunction, - graphqlRunner, - websocketManager, - } - }, - onDone: [ - { - target: `startingDevServers`, - cond: ({ compiler }: IBuildContext): boolean => !compiler, - }, - { - target: `waiting`, - }, - ], - }, - }, - startingDevServers: { - invoke: { - src: `startWebpackServer`, - onDone: { - target: `waiting`, - actions: `assignServers`, - }, - }, - }, - waiting: { - on: { - ADD_NODE_MUTATION: { - actions: forwardTo(`waiting`), - }, - QUERY_FILE_CHANGED: { - actions: forwardTo(`waiting`), - }, - EXTRACT_QUERIES_NOW: { - target: `runningQueries`, - }, - }, - invoke: { - id: `waiting`, - src: `waitForMutations`, - data: ({ - store, - nodeMutationBatch = [], - }: IBuildContext): IWaitingContext => { - return { store, nodeMutationBatch, runningBatch: [] } - }, - onDone: { - actions: `assignServiceResult`, - target: `rebuildingPages`, - }, - }, - }, - rebuildingPages: { - invoke: { - src: `initializeDataLayer`, - data: ({ parentSpan, store }: IBuildContext): IDataLayerContext => { - return { parentSpan, store, firstRun: false, skipSourcing: true } - }, - onDone: { - actions: `assignServiceResult`, - target: `runningQueries`, - }, - }, - }, - }, - // Transitions shared by all states, except where overridden - on: { - ADD_NODE_MUTATION: { - actions: `addNodeMutation`, - }, - QUERY_FILE_CHANGED: { - actions: `markQueryFilesDirty`, - }, - WEBHOOK_RECEIVED: { - target: `initializingDataLayer`, - actions: `assignWebhookBody`, - }, - }, - } - - const machine = Machine(developConfig, { - services: { - initializeDataLayer: dataLayerMachine, - initialize, - runQueries: queryRunningMachine, - waitForMutations: waitingMachine, - startWebpackServer: startWebpackServer, - }, - actions: buildActions, - }).withContext({ program, parentSpan: bootstrapSpan, app, firstRun: true }) + const machine = developMachine.withContext({ + program, + parentSpan, + app, + firstRun: true, + }) const service = interpret(machine) diff --git a/packages/gatsby/src/state-machines/data-layer/actions.ts b/packages/gatsby/src/state-machines/data-layer/actions.ts index 6ff1e2491da3e..0ae2747a536d4 100644 --- a/packages/gatsby/src/state-machines/data-layer/actions.ts +++ b/packages/gatsby/src/state-machines/data-layer/actions.ts @@ -2,7 +2,7 @@ import { assign, DoneInvokeEvent, ActionFunctionMap } from "xstate" import { createGraphQLRunner } from "../../bootstrap/create-graphql-runner" import reporter from "gatsby-cli/lib/reporter" import { IDataLayerContext } from "./types" -import { callApi, markNodesDirty } from "../actions" +import { callApi, markNodesDirty } from "../develop/actions" import { assertStore } from "../../utils/assert-store" import { GraphQLRunner } from "../../query/graphql-runner" diff --git a/packages/gatsby/src/state-machines/actions.ts b/packages/gatsby/src/state-machines/develop/actions.ts similarity index 90% rename from packages/gatsby/src/state-machines/actions.ts rename to packages/gatsby/src/state-machines/develop/actions.ts index 114693dac9ed6..fbe90a863081d 100644 --- a/packages/gatsby/src/state-machines/actions.ts +++ b/packages/gatsby/src/state-machines/develop/actions.ts @@ -7,11 +7,11 @@ import { DoneEventObject, } from "xstate" import { Store } from "redux" -import { IBuildContext, IMutationAction } from "../services" -import { actions } from "../redux/actions" -import { listenForMutations } from "../services/listen-for-mutations" -import { DataLayerResult } from "./data-layer" -import { assertStore } from "../utils/assert-store" +import { IBuildContext, IMutationAction } from "../../services" +import { actions } from "../../redux/actions" +import { listenForMutations } from "../../services/listen-for-mutations" +import { DataLayerResult } from "../data-layer" +import { assertStore } from "../../utils/assert-store" import reporter from "gatsby-cli/lib/reporter" export const callRealApi = (event: IMutationAction, store?: Store): void => { diff --git a/packages/gatsby/src/state-machines/develop/index.ts b/packages/gatsby/src/state-machines/develop/index.ts new file mode 100644 index 0000000000000..440e9c7e4fb15 --- /dev/null +++ b/packages/gatsby/src/state-machines/develop/index.ts @@ -0,0 +1,170 @@ +import { MachineConfig, AnyEventObject, forwardTo, Machine } from "xstate" +import { runMutationAndMarkDirty } from "../shared-transition-configs" +import { IDataLayerContext } from "../data-layer/types" +import { IQueryRunningContext } from "../query-running/types" +import { IWaitingContext } from "../waiting/types" +import { buildActions } from "./actions" +import { developServices } from "./services" +import { IBuildContext } from "../../services" + +/** + * This is the top-level state machine for the `gatsby develop` command + */ +const developConfig: MachineConfig = { + id: `build`, + initial: `initializing`, + states: { + initializing: { + on: { + // Ignore mutation events because we'll be running everything anyway + ADD_NODE_MUTATION: undefined, + QUERY_FILE_CHANGED: undefined, + WEBHOOK_RECEIVED: undefined, + }, + invoke: { + src: `initialize`, + onDone: { + target: `initializingDataLayer`, + actions: [`assignStoreAndWorkerPool`, `spawnMutationListener`], + }, + }, + }, + initializingDataLayer: { + on: { + ADD_NODE_MUTATION: runMutationAndMarkDirty, + // Ignore, because we're about to extract them anyway + QUERY_FILE_CHANGED: undefined, + }, + invoke: { + src: `initializeDataLayer`, + data: ({ + parentSpan, + store, + firstRun, + webhookBody, + }: IBuildContext): IDataLayerContext => { + return { + parentSpan, + store, + firstRun, + deferNodeMutation: true, + webhookBody, + } + }, + onDone: { + actions: [ + `assignServiceResult`, + `clearWebhookBody`, + `finishParentSpan`, + ], + target: `finishingBootstrap`, + }, + }, + }, + runningQueries: { + on: { + QUERY_FILE_CHANGED: { + actions: forwardTo(`run-queries`), + }, + }, + invoke: { + id: `run-queries`, + src: `runQueries`, + data: ({ + program, + store, + parentSpan, + gatsbyNodeGraphQLFunction, + graphqlRunner, + websocketManager, + firstRun, + }: IBuildContext): IQueryRunningContext => { + return { + firstRun, + program, + store, + parentSpan, + gatsbyNodeGraphQLFunction, + graphqlRunner, + websocketManager, + } + }, + onDone: [ + { + target: `startingDevServers`, + cond: ({ compiler }: IBuildContext): boolean => !compiler, + }, + { + target: `waiting`, + }, + ], + }, + }, + startingDevServers: { + invoke: { + src: `startWebpackServer`, + onDone: { + target: `waiting`, + actions: `assignServers`, + }, + }, + }, + waiting: { + on: { + ADD_NODE_MUTATION: { + actions: forwardTo(`waiting`), + }, + QUERY_FILE_CHANGED: { + actions: forwardTo(`waiting`), + }, + EXTRACT_QUERIES_NOW: { + target: `runningQueries`, + }, + }, + invoke: { + id: `waiting`, + src: `waitForMutations`, + data: ({ + store, + nodeMutationBatch = [], + }: IBuildContext): IWaitingContext => { + return { store, nodeMutationBatch, runningBatch: [] } + }, + onDone: { + actions: `assignServiceResult`, + target: `rebuildingPages`, + }, + }, + }, + rebuildingPages: { + invoke: { + src: `initializeDataLayer`, + data: ({ parentSpan, store }: IBuildContext): IDataLayerContext => { + return { parentSpan, store, firstRun: false, skipSourcing: true } + }, + onDone: { + actions: `assignServiceResult`, + target: `runningQueries`, + }, + }, + }, + }, + // Transitions shared by all states, except where overridden + on: { + ADD_NODE_MUTATION: { + actions: `addNodeMutation`, + }, + QUERY_FILE_CHANGED: { + actions: `markQueryFilesDirty`, + }, + WEBHOOK_RECEIVED: { + target: `initializingDataLayer`, + actions: `assignWebhookBody`, + }, + }, +} + +export const developMachine = Machine(developConfig, { + services: developServices, + actions: buildActions, +}) diff --git a/packages/gatsby/src/state-machines/develop/services.ts b/packages/gatsby/src/state-machines/develop/services.ts new file mode 100644 index 0000000000000..a233e8eadacf3 --- /dev/null +++ b/packages/gatsby/src/state-machines/develop/services.ts @@ -0,0 +1,13 @@ +import { IBuildContext, startWebpackServer, initialize } from "../../services" +import { dataLayerMachine } from "../data-layer" +import { queryRunningMachine } from "../query-running" +import { waitingMachine } from "../waiting" +import { ServiceConfig } from "xstate" + +export const developServices: Record> = { + initializeDataLayer: dataLayerMachine, + initialize: initialize, + runQueries: queryRunningMachine, + waitForMutations: waitingMachine, + startWebpackServer: startWebpackServer, +} From b50e996c3948046bfd1a254baec9a6a048f0e53a Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Mon, 13 Jul 2020 11:14:41 +0100 Subject: [PATCH 3/4] Add machine ids --- packages/gatsby/src/state-machines/data-layer/index.ts | 1 + packages/gatsby/src/state-machines/query-running/index.ts | 1 + packages/gatsby/src/state-machines/waiting/index.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/packages/gatsby/src/state-machines/data-layer/index.ts b/packages/gatsby/src/state-machines/data-layer/index.ts index ef9a3171f2c9a..1e70213e1fa5f 100644 --- a/packages/gatsby/src/state-machines/data-layer/index.ts +++ b/packages/gatsby/src/state-machines/data-layer/index.ts @@ -13,6 +13,7 @@ export type DataLayerResult = Pick< const dataLayerStates: MachineConfig = { initial: `start`, + id: `dataLayerMachine`, context: {}, states: { start: { diff --git a/packages/gatsby/src/state-machines/query-running/index.ts b/packages/gatsby/src/state-machines/query-running/index.ts index 63290140827fa..b20daa6d01258 100644 --- a/packages/gatsby/src/state-machines/query-running/index.ts +++ b/packages/gatsby/src/state-machines/query-running/index.ts @@ -10,6 +10,7 @@ const extractQueriesIfFilesAreDirty = { export const queryStates: MachineConfig = { initial: `extractingQueries`, + id: `queryRunningMachine`, context: {}, states: { extractingQueries: { diff --git a/packages/gatsby/src/state-machines/waiting/index.ts b/packages/gatsby/src/state-machines/waiting/index.ts index 7cab16825cef5..6446c194afeeb 100644 --- a/packages/gatsby/src/state-machines/waiting/index.ts +++ b/packages/gatsby/src/state-machines/waiting/index.ts @@ -9,6 +9,7 @@ const NODE_MUTATION_BATCH_TIMEOUT = 1000 export type WaitingResult = Pick export const waitingStates: MachineConfig = { + id: `waitingMachine`, initial: `idle`, context: { nodeMutationBatch: [], From 09ff65b217517017ebcdbc636464ff75a8143335 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Mon, 13 Jul 2020 11:15:14 +0100 Subject: [PATCH 4/4] Add missing imports --- .../src/state-machines/data-layer/services.ts | 4 ++++ .../src/state-machines/develop/actions.ts | 2 +- .../gatsby/src/state-machines/develop/index.ts | 7 ++++--- .../shared-transition-configs.ts | 18 ------------------ 4 files changed, 9 insertions(+), 22 deletions(-) delete mode 100644 packages/gatsby/src/state-machines/shared-transition-configs.ts diff --git a/packages/gatsby/src/state-machines/data-layer/services.ts b/packages/gatsby/src/state-machines/data-layer/services.ts index fd04e3c19df98..4871e90d2d0a1 100644 --- a/packages/gatsby/src/state-machines/data-layer/services.ts +++ b/packages/gatsby/src/state-machines/data-layer/services.ts @@ -5,6 +5,8 @@ import { createPagesStatefully, buildSchema, sourceNodes, + rebuildSchemaWithSitePage, + writeOutRedirects, } from "../../services" import { IDataLayerContext } from "./types" @@ -17,4 +19,6 @@ export const dataLayerServices: Record< createPages, buildSchema, createPagesStatefully, + rebuildSchemaWithSitePage, + writeOutRedirects, } diff --git a/packages/gatsby/src/state-machines/develop/actions.ts b/packages/gatsby/src/state-machines/develop/actions.ts index fbe90a863081d..c5d22becb03ad 100644 --- a/packages/gatsby/src/state-machines/develop/actions.ts +++ b/packages/gatsby/src/state-machines/develop/actions.ts @@ -109,5 +109,5 @@ export const buildActions: ActionFunctionMap = { markQueryFilesDirty, assignWebhookBody, clearWebhookBody, - finishBootstrapSpan: finishParentSpan, + finishParentSpan, } diff --git a/packages/gatsby/src/state-machines/develop/index.ts b/packages/gatsby/src/state-machines/develop/index.ts index 440e9c7e4fb15..7b37579b01ccb 100644 --- a/packages/gatsby/src/state-machines/develop/index.ts +++ b/packages/gatsby/src/state-machines/develop/index.ts @@ -1,5 +1,4 @@ import { MachineConfig, AnyEventObject, forwardTo, Machine } from "xstate" -import { runMutationAndMarkDirty } from "../shared-transition-configs" import { IDataLayerContext } from "../data-layer/types" import { IQueryRunningContext } from "../query-running/types" import { IWaitingContext } from "../waiting/types" @@ -31,7 +30,9 @@ const developConfig: MachineConfig = { }, initializingDataLayer: { on: { - ADD_NODE_MUTATION: runMutationAndMarkDirty, + ADD_NODE_MUTATION: { + actions: [`markNodesDirty`, `callApi`], + }, // Ignore, because we're about to extract them anyway QUERY_FILE_CHANGED: undefined, }, @@ -57,7 +58,7 @@ const developConfig: MachineConfig = { `clearWebhookBody`, `finishParentSpan`, ], - target: `finishingBootstrap`, + target: `runningQueries`, }, }, }, diff --git a/packages/gatsby/src/state-machines/shared-transition-configs.ts b/packages/gatsby/src/state-machines/shared-transition-configs.ts deleted file mode 100644 index 9507e31369319..0000000000000 --- a/packages/gatsby/src/state-machines/shared-transition-configs.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Event handler used in all states where we're not ready to process a file change - * Instead we add it to a batch to process when we're next idle - */ -// export const SOURCE_FILE_CHANGED: TransitionConfig< -// Pick, -// AnyEventObject -// > = { -// actions: `markFilesDirty`, -// } - -/** - * When running queries we might add nodes (e.g from resolvers). If so we'll - * want to re-run queries and schema inference - */ -export const runMutationAndMarkDirty = { - actions: [`markNodesDirty`, `callApi`], -}