From bb08162f84fc64a925ad8f2ea6af203b65a9a4fa Mon Sep 17 00:00:00 2001 From: LekoArts Date: Tue, 9 Aug 2022 11:46:03 +0200 Subject: [PATCH 1/9] update version and fix types --- packages/gatsby-source-filesystem/package.json | 2 +- packages/gatsby/package.json | 2 +- packages/gatsby/src/commands/develop-process.ts | 1 + .../gatsby/src/state-machines/data-layer/services.ts | 10 +++++----- packages/gatsby/src/state-machines/develop/services.ts | 4 ++-- .../src/state-machines/query-running/services.ts | 10 +++++----- yarn.lock | 8 ++++---- 7 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/gatsby-source-filesystem/package.json b/packages/gatsby-source-filesystem/package.json index bf558d7e5d0d7..9606004542b77 100644 --- a/packages/gatsby-source-filesystem/package.json +++ b/packages/gatsby-source-filesystem/package.json @@ -18,7 +18,7 @@ "pretty-bytes": "^5.4.1", "progress": "^2.0.3", "valid-url": "^1.0.9", - "xstate": "^4.26.1" + "xstate": "^4.33.0" }, "devDependencies": { "@babel/cli": "^7.15.4", diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index eac67d1d7440e..043ab3c09a2d5 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -168,7 +168,7 @@ "webpack-merge": "^5.8.0", "webpack-stats-plugin": "^1.0.3", "webpack-virtual-modules": "^0.3.2", - "xstate": "^4.26.0", + "xstate": "^4.33.0", "yaml-loader": "^0.6.0" }, "devDependencies": { diff --git a/packages/gatsby/src/commands/develop-process.ts b/packages/gatsby/src/commands/develop-process.ts index 17996b56909b4..178f00c9f1254 100644 --- a/packages/gatsby/src/commands/develop-process.ts +++ b/packages/gatsby/src/commands/develop-process.ts @@ -164,6 +164,7 @@ module.exports = async (program: IDevelopArgs): Promise => { const service = interpret(machine) if (program.verbose) { + // @ts-ignore - I don't understand this failure logTransitions(service) } diff --git a/packages/gatsby/src/state-machines/data-layer/services.ts b/packages/gatsby/src/state-machines/data-layer/services.ts index 3dd8e34ebf8b5..9195d8fc9647f 100644 --- a/packages/gatsby/src/state-machines/data-layer/services.ts +++ b/packages/gatsby/src/state-machines/data-layer/services.ts @@ -1,4 +1,4 @@ -import { ServiceConfig } from "xstate" +import { MachineOptions } from "xstate" import { customizeSchema, createPages, @@ -8,10 +8,10 @@ import { } from "../../services" import { IDataLayerContext } from "./types" -export const dataLayerServices: Record< - string, - ServiceConfig -> = { +export const dataLayerServices: MachineOptions< + IDataLayerContext, + any +>["services"] = { customizeSchema, sourceNodes, createPages, diff --git a/packages/gatsby/src/state-machines/develop/services.ts b/packages/gatsby/src/state-machines/develop/services.ts index eb2f5d7a5a280..04f76043ac9af 100644 --- a/packages/gatsby/src/state-machines/develop/services.ts +++ b/packages/gatsby/src/state-machines/develop/services.ts @@ -13,9 +13,9 @@ import { } from "../data-layer" import { queryRunningMachine } from "../query-running" import { waitingMachine } from "../waiting" -import { ServiceConfig } from "xstate" +import { MachineOptions } from "xstate" -export const developServices: Record> = { +export const developServices: MachineOptions["services"] = { initializeData: initializeDataMachine, reloadData: reloadDataMachine, recreatePages: recreatePagesMachine, diff --git a/packages/gatsby/src/state-machines/query-running/services.ts b/packages/gatsby/src/state-machines/query-running/services.ts index 499e6898aa143..08bb68f0f8455 100644 --- a/packages/gatsby/src/state-machines/query-running/services.ts +++ b/packages/gatsby/src/state-machines/query-running/services.ts @@ -1,4 +1,4 @@ -import { ServiceConfig } from "xstate" +import { MachineOptions } from "xstate" import { extractQueries, writeOutRequires, @@ -10,10 +10,10 @@ import { } from "../../services" import { IQueryRunningContext } from "./types" -export const queryRunningServices: Record< - string, - ServiceConfig -> = { +export const queryRunningServices: MachineOptions< + IQueryRunningContext, + any +>["services"] = { extractQueries, writeOutRequires, calculateDirtyQueries, diff --git a/yarn.lock b/yarn.lock index 27755c03a8c6c..72d7deeead175 100644 --- a/yarn.lock +++ b/yarn.lock @@ -26160,10 +26160,10 @@ xss@^1.0.6: commander "^2.20.3" cssfilter "0.0.10" -xstate@^4.26.0, xstate@^4.26.1: - version "4.26.1" - resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.26.1.tgz#4fc1afd153f88cf302a9ee2b758f6629e6a829b6" - integrity sha512-JLofAEnN26l/1vbODgsDa+Phqa61PwDlxWu8+2pK+YbXf+y9pQSDLRvcYH2H1kkeUBA5fGp+xFL/zfE8jNMw4g== +xstate@^4.33.0: + version "4.33.0" + resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.33.0.tgz#4377a11e92267ad01ea498c4fc69887f0eddf1c8" + integrity sha512-+oari/Nt2cBq79mklnGA9Tsb6kv7ln+cIMfrH6n642XpTEG6sMRHg4GkooAbGbcslG3Ff9uH2jmGRP+1uoZ/Xw== xtend@^4.0.0, xtend@^4.0.1, xtend@^4.0.2, xtend@~4.0.0, xtend@~4.0.1: version "4.0.2" From 62bb7400d165ad81600df7eddaa1fb40eb733447 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Tue, 9 Aug 2022 11:51:23 +0200 Subject: [PATCH 2/9] yolo add option --- packages/gatsby-source-filesystem/src/gatsby-node.js | 5 +++-- packages/gatsby/src/state-machines/data-layer/index.ts | 3 +++ packages/gatsby/src/state-machines/develop/index.ts | 1 + packages/gatsby/src/state-machines/query-running/index.ts | 1 + packages/gatsby/src/state-machines/waiting/index.ts | 1 + 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-filesystem/src/gatsby-node.js b/packages/gatsby-source-filesystem/src/gatsby-node.js index 8a2d70003962d..4a44eccb21426 100644 --- a/packages/gatsby-source-filesystem/src/gatsby-node.js +++ b/packages/gatsby-source-filesystem/src/gatsby-node.js @@ -1,7 +1,7 @@ const chokidar = require(`chokidar`) const fs = require(`fs`) const path = require(`path`) -const { Machine, interpret } = require(`xstate`) +const { createMachine, interpret } = require(`xstate`) const { createFileNode } = require(`./create-file-node`) const { ERROR_MAP } = require(`./error-utils`) @@ -66,8 +66,9 @@ const createFSMachine = ( } } - const fsMachine = Machine( + const fsMachine = createMachine( { + predictableActionArguments: true, id: `fs`, type: `parallel`, states: { diff --git a/packages/gatsby/src/state-machines/data-layer/index.ts b/packages/gatsby/src/state-machines/data-layer/index.ts index 121a50b3769dd..14b38ef92162f 100644 --- a/packages/gatsby/src/state-machines/data-layer/index.ts +++ b/packages/gatsby/src/state-machines/data-layer/index.ts @@ -117,6 +117,7 @@ const options: Partial> = { export const initializeDataMachine = createMachine( { + predictableActionArguments: true, id: `initializeDataMachine`, context: {}, initial: `customizingSchema`, @@ -135,6 +136,7 @@ export const initializeDataMachine = createMachine( export const reloadDataMachine = createMachine( { + predictableActionArguments: true, id: `reloadDataMachine`, context: {}, initial: `customizingSchema`, @@ -153,6 +155,7 @@ export const reloadDataMachine = createMachine( */ export const recreatePagesMachine = createMachine( { + predictableActionArguments: true, id: `recreatePagesMachine`, context: {}, initial: `buildingSchema`, diff --git a/packages/gatsby/src/state-machines/develop/index.ts b/packages/gatsby/src/state-machines/develop/index.ts index db77855369f0f..294a95e827a02 100644 --- a/packages/gatsby/src/state-machines/develop/index.ts +++ b/packages/gatsby/src/state-machines/develop/index.ts @@ -21,6 +21,7 @@ const getGraphqlTypegenConfig = (ctx: IBuildContext): boolean => * This is the top-level state machine for the `gatsby develop` command */ const developConfig: MachineConfig = { + predictableActionArguments: true, id: `build`, initial: `initializing`, // These are mutation events, sent to this machine by the mutation listener diff --git a/packages/gatsby/src/state-machines/query-running/index.ts b/packages/gatsby/src/state-machines/query-running/index.ts index d39409a5841d8..3b935dd13e210 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 @@ import { queryActions } from "./actions" const PAGE_QUERY_ENQUEUING_TIMEOUT = 50 export const queryStates: MachineConfig = { + predictableActionArguments: true, initial: `extractingQueries`, id: `queryRunningMachine`, on: { diff --git a/packages/gatsby/src/state-machines/waiting/index.ts b/packages/gatsby/src/state-machines/waiting/index.ts index 74a7d137370b2..f8ba58fd0da8a 100644 --- a/packages/gatsby/src/state-machines/waiting/index.ts +++ b/packages/gatsby/src/state-machines/waiting/index.ts @@ -14,6 +14,7 @@ export type WaitingResult = Pick * mutations when we first start it */ export const waitingStates: MachineConfig = { + predictableActionArguments: true, id: `waitingMachine`, initial: `idle`, context: { From efb5d12320eb66fa82f5b0e81cda49fc6ba3d46e Mon Sep 17 00:00:00 2001 From: tyhopp Date: Wed, 10 Aug 2022 16:17:56 +0800 Subject: [PATCH 3/9] Work around removal of meta.state --- packages/gatsby-source-filesystem/src/gatsby-node.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-filesystem/src/gatsby-node.js b/packages/gatsby-source-filesystem/src/gatsby-node.js index 4a44eccb21426..b3e2c2ba1d32e 100644 --- a/packages/gatsby-source-filesystem/src/gatsby-node.js +++ b/packages/gatsby-source-filesystem/src/gatsby-node.js @@ -61,7 +61,7 @@ const createFSMachine = ( } const log = expr => (ctx, action, meta) => { - if (meta.state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) { + if (machineInstance.state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) { reporter.info(expr(ctx, action, meta)) } } @@ -151,7 +151,8 @@ const createFSMachine = ( }, } ) - return interpret(fsMachine).start() + const machineInstance = interpret(fsMachine).start() + return machineInstance } exports.pluginOptionsSchema = ({ Joi }) => From 84db26372d7d55ab64aba7907c4ff1395e1d2a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 10 Aug 2022 15:15:00 +0200 Subject: [PATCH 4/9] Refactor `meta.state` access in `gatsby-source-filesystem` (#36355) Co-authored-by: Lennart --- packages/gatsby-source-filesystem/src/gatsby-node.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/gatsby-source-filesystem/src/gatsby-node.js b/packages/gatsby-source-filesystem/src/gatsby-node.js index b3e2c2ba1d32e..15ddd7e514033 100644 --- a/packages/gatsby-source-filesystem/src/gatsby-node.js +++ b/packages/gatsby-source-filesystem/src/gatsby-node.js @@ -1,7 +1,7 @@ const chokidar = require(`chokidar`) const fs = require(`fs`) const path = require(`path`) -const { createMachine, interpret } = require(`xstate`) +const { createMachine, interpret, assign } = require(`xstate`) const { createFileNode } = require(`./create-file-node`) const { ERROR_MAP } = require(`./error-utils`) @@ -61,7 +61,7 @@ const createFSMachine = ( } const log = expr => (ctx, action, meta) => { - if (machineInstance.state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) { + if (ctx.bootstrapped) { reporter.info(expr(ctx, action, meta)) } } @@ -69,6 +69,9 @@ const createFSMachine = ( const fsMachine = createMachine( { predictableActionArguments: true, + context: { + bootstrapped: false, + }, id: `fs`, type: `parallel`, states: { @@ -82,6 +85,7 @@ const createFSMachine = ( }, BOOTSTRAPPED: { type: `final`, + entry: assign({ bootstrapped: true }), }, }, }, @@ -151,8 +155,7 @@ const createFSMachine = ( }, } ) - const machineInstance = interpret(fsMachine).start() - return machineInstance + return interpret(fsMachine).start() } exports.pluginOptionsSchema = ({ Joi }) => From df3ae074bace232a8377ca5c2849fa7e9274e7a9 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 11 Aug 2022 07:43:47 +0200 Subject: [PATCH 5/9] fix ts-ignore --- packages/gatsby/src/commands/develop-process.ts | 1 - packages/gatsby/src/utils/state-machine-logging.ts | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/commands/develop-process.ts b/packages/gatsby/src/commands/develop-process.ts index 178f00c9f1254..17996b56909b4 100644 --- a/packages/gatsby/src/commands/develop-process.ts +++ b/packages/gatsby/src/commands/develop-process.ts @@ -164,7 +164,6 @@ module.exports = async (program: IDevelopArgs): Promise => { const service = interpret(machine) if (program.verbose) { - // @ts-ignore - I don't understand this failure logTransitions(service) } diff --git a/packages/gatsby/src/utils/state-machine-logging.ts b/packages/gatsby/src/utils/state-machine-logging.ts index fb448d4cdd6ab..ab604e6a4c1e1 100644 --- a/packages/gatsby/src/utils/state-machine-logging.ts +++ b/packages/gatsby/src/utils/state-machine-logging.ts @@ -7,12 +7,14 @@ import { } from "xstate" import reporter from "gatsby-cli/lib/reporter" +type AnyInterpreterWithContext = Interpreter + const isInterpreter = ( actor: Actor | Interpreter ): actor is Interpreter => `machine` in actor export function logTransitions( - service: Interpreter + service: AnyInterpreterWithContext ): void { const listeners = new WeakSet() let last: State From d4e1f89043f4c68da3ee8a460f1128655d0102cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 16 Nov 2022 10:46:17 +0100 Subject: [PATCH 6/9] Upgrade XState to the latest 4.33.3 (#36451) --- packages/gatsby-source-filesystem/package.json | 2 +- packages/gatsby/package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/gatsby-source-filesystem/package.json b/packages/gatsby-source-filesystem/package.json index 27cba646bd756..559d1e270becf 100644 --- a/packages/gatsby-source-filesystem/package.json +++ b/packages/gatsby-source-filesystem/package.json @@ -16,7 +16,7 @@ "mime": "^2.5.2", "pretty-bytes": "^5.4.1", "valid-url": "^1.0.9", - "xstate": "^4.33.0" + "xstate": "4.33.3" }, "devDependencies": { "@babel/cli": "^7.15.4", diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index b8b9a1affe434..638d1f8ea1b00 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -169,7 +169,7 @@ "webpack-merge": "^5.8.0", "webpack-stats-plugin": "^1.0.3", "webpack-virtual-modules": "^0.3.2", - "xstate": "^4.33.0", + "xstate": "4.33.3", "yaml-loader": "^0.6.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index e2b85cfc7d9e3..48b14c787757d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -26949,10 +26949,10 @@ xss@^1.0.6: commander "^2.20.3" cssfilter "0.0.10" -xstate@^4.33.0: - version "4.33.0" - resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.33.0.tgz#4377a11e92267ad01ea498c4fc69887f0eddf1c8" - integrity sha512-+oari/Nt2cBq79mklnGA9Tsb6kv7ln+cIMfrH6n642XpTEG6sMRHg4GkooAbGbcslG3Ff9uH2jmGRP+1uoZ/Xw== +xstate@4.33.3: + version "4.33.3" + resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.33.3.tgz#a1c0a60626f79e8563f5ec6c55da058bab0ed563" + integrity sha512-NXFGDFXlDg04dYaKwAlHGeCT6K4bcYiXndaG1p9g++1z2FnEUji6chfZ2lxYc28pcV6tz1vAsfaSJdgZUS4J/w== xtend@^4.0.0, xtend@^4.0.1, xtend@^4.0.2, xtend@~4.0.0, xtend@~4.0.1: version "4.0.2" From ce74ec56eedc0bab521d92fcf9d4727e834c80a5 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Wed, 16 Nov 2022 10:49:49 +0100 Subject: [PATCH 7/9] update to latest xstate --- packages/gatsby-source-filesystem/package.json | 2 +- packages/gatsby/package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/gatsby-source-filesystem/package.json b/packages/gatsby-source-filesystem/package.json index 21596a6e5abda..192fdcf6185f1 100644 --- a/packages/gatsby-source-filesystem/package.json +++ b/packages/gatsby-source-filesystem/package.json @@ -16,7 +16,7 @@ "mime": "^2.5.2", "pretty-bytes": "^5.4.1", "valid-url": "^1.0.9", - "xstate": "4.33.3" + "xstate": "^4.34.0" }, "devDependencies": { "@babel/cli": "^7.15.4", diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index 3c8607ad81dec..06d9fdb01c9b0 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -173,7 +173,7 @@ "webpack-merge": "^5.8.0", "webpack-stats-plugin": "^1.0.3", "webpack-virtual-modules": "^0.3.2", - "xstate": "4.33.3", + "xstate": "^4.34.0", "yaml-loader": "^0.6.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 3f587ad64c8e4..b1359fe682628 100644 --- a/yarn.lock +++ b/yarn.lock @@ -24750,10 +24750,10 @@ xmlhttprequest-ssl@~1.5.4: version "1.5.5" resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz#c2876b06168aadc40e57d97e81191ac8f4398b3e" -xstate@4.33.3: - version "4.33.3" - resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.33.3.tgz#a1c0a60626f79e8563f5ec6c55da058bab0ed563" - integrity sha512-NXFGDFXlDg04dYaKwAlHGeCT6K4bcYiXndaG1p9g++1z2FnEUji6chfZ2lxYc28pcV6tz1vAsfaSJdgZUS4J/w== +xstate@^4.34.0: + version "4.34.0" + resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.34.0.tgz#401901c478f0b2a7f07576c020b6e6f750b5bd10" + integrity sha512-MFnYz7cJrWuXSZ8IPkcCyLB1a2T3C71kzMeShXKmNaEjBR/JQebKZPHTtxHKZpymESaWO31rA3IQ30TC6LW+sw== xtend@^4.0.0, xtend@^4.0.1, xtend@^4.0.2, xtend@~4.0.0, xtend@~4.0.1: version "4.0.2" From 9460dd35900d51e45d159cc9d9f153df2f938fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 16 Nov 2022 10:55:50 +0100 Subject: [PATCH 8/9] Use `pendingQueryRuns` available on the event (#36393) --- .../gatsby/src/services/calculate-dirty-queries.ts | 13 ++++++++----- .../src/state-machines/query-running/actions.ts | 6 ------ .../src/state-machines/query-running/index.ts | 12 +++--------- .../src/state-machines/query-running/types.ts | 1 - 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/packages/gatsby/src/services/calculate-dirty-queries.ts b/packages/gatsby/src/services/calculate-dirty-queries.ts index f7d694236554e..9b845615e657e 100644 --- a/packages/gatsby/src/services/calculate-dirty-queries.ts +++ b/packages/gatsby/src/services/calculate-dirty-queries.ts @@ -3,11 +3,14 @@ import { IGroupedQueryIds } from "./" import { IQueryRunningContext } from "../state-machines/query-running/types" import { assertStore } from "../utils/assert-store" -export async function calculateDirtyQueries({ - store, - websocketManager, - currentlyHandledPendingQueryRuns, -}: Partial): Promise<{ +export async function calculateDirtyQueries( + { store, websocketManager }: Partial, + { + pendingQueryRuns: currentlyHandledPendingQueryRuns, + }: { + pendingQueryRuns?: Set + } = {} +): Promise<{ queryIds: IGroupedQueryIds }> { assertStore(store) diff --git a/packages/gatsby/src/state-machines/query-running/actions.ts b/packages/gatsby/src/state-machines/query-running/actions.ts index 46cd9823d613a..987c772716627 100644 --- a/packages/gatsby/src/state-machines/query-running/actions.ts +++ b/packages/gatsby/src/state-machines/query-running/actions.ts @@ -42,16 +42,10 @@ export const trackRequestedQueryRun = assign< }, }) -export const clearCurrentlyHandledPendingQueryRuns = - assign({ - currentlyHandledPendingQueryRuns: undefined, - }) - export const queryActions: ActionFunctionMap = { assignDirtyQueries, flushPageData, markSourceFilesDirty, markSourceFilesClean, trackRequestedQueryRun, - clearCurrentlyHandledPendingQueryRuns, } diff --git a/packages/gatsby/src/state-machines/query-running/index.ts b/packages/gatsby/src/state-machines/query-running/index.ts index 5b791316adfdc..47d1e7d4470ef 100644 --- a/packages/gatsby/src/state-machines/query-running/index.ts +++ b/packages/gatsby/src/state-machines/query-running/index.ts @@ -62,21 +62,15 @@ export const queryStates: MachineConfig = { }, }, calculatingDirtyQueries: { - entry: assign(({ pendingQueryRuns }) => { - return { - pendingQueryRuns: new Set(), - currentlyHandledPendingQueryRuns: pendingQueryRuns, - } + entry: assign({ + pendingQueryRuns: new Set(), }), invoke: { id: `calculating-dirty-queries`, src: `calculateDirtyQueries`, onDone: { target: `runningStaticQueries`, - actions: [ - `assignDirtyQueries`, - `clearCurrentlyHandledPendingQueryRuns`, - ], + actions: [`assignDirtyQueries`], }, }, }, diff --git a/packages/gatsby/src/state-machines/query-running/types.ts b/packages/gatsby/src/state-machines/query-running/types.ts index e7ee8420ed7bd..269b59df779c3 100644 --- a/packages/gatsby/src/state-machines/query-running/types.ts +++ b/packages/gatsby/src/state-machines/query-running/types.ts @@ -23,5 +23,4 @@ export interface IQueryRunningContext { websocketManager?: WebsocketManager filesDirty?: boolean pendingQueryRuns?: Set - currentlyHandledPendingQueryRuns?: Set } From 7b02bb8ba0ce463eadff8c8bc5f41a308ee39f55 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Wed, 16 Nov 2022 11:25:01 +0100 Subject: [PATCH 9/9] Revert "Use `pendingQueryRuns` available on the event (#36393)" This reverts commit 9460dd35900d51e45d159cc9d9f153df2f938fe6. --- .../gatsby/src/services/calculate-dirty-queries.ts | 13 +++++-------- .../src/state-machines/query-running/actions.ts | 6 ++++++ .../src/state-machines/query-running/index.ts | 12 +++++++++--- .../src/state-machines/query-running/types.ts | 1 + 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/gatsby/src/services/calculate-dirty-queries.ts b/packages/gatsby/src/services/calculate-dirty-queries.ts index 9b845615e657e..f7d694236554e 100644 --- a/packages/gatsby/src/services/calculate-dirty-queries.ts +++ b/packages/gatsby/src/services/calculate-dirty-queries.ts @@ -3,14 +3,11 @@ import { IGroupedQueryIds } from "./" import { IQueryRunningContext } from "../state-machines/query-running/types" import { assertStore } from "../utils/assert-store" -export async function calculateDirtyQueries( - { store, websocketManager }: Partial, - { - pendingQueryRuns: currentlyHandledPendingQueryRuns, - }: { - pendingQueryRuns?: Set - } = {} -): Promise<{ +export async function calculateDirtyQueries({ + store, + websocketManager, + currentlyHandledPendingQueryRuns, +}: Partial): Promise<{ queryIds: IGroupedQueryIds }> { assertStore(store) diff --git a/packages/gatsby/src/state-machines/query-running/actions.ts b/packages/gatsby/src/state-machines/query-running/actions.ts index 987c772716627..46cd9823d613a 100644 --- a/packages/gatsby/src/state-machines/query-running/actions.ts +++ b/packages/gatsby/src/state-machines/query-running/actions.ts @@ -42,10 +42,16 @@ export const trackRequestedQueryRun = assign< }, }) +export const clearCurrentlyHandledPendingQueryRuns = + assign({ + currentlyHandledPendingQueryRuns: undefined, + }) + export const queryActions: ActionFunctionMap = { assignDirtyQueries, flushPageData, markSourceFilesDirty, markSourceFilesClean, trackRequestedQueryRun, + clearCurrentlyHandledPendingQueryRuns, } diff --git a/packages/gatsby/src/state-machines/query-running/index.ts b/packages/gatsby/src/state-machines/query-running/index.ts index 47d1e7d4470ef..5b791316adfdc 100644 --- a/packages/gatsby/src/state-machines/query-running/index.ts +++ b/packages/gatsby/src/state-machines/query-running/index.ts @@ -62,15 +62,21 @@ export const queryStates: MachineConfig = { }, }, calculatingDirtyQueries: { - entry: assign({ - pendingQueryRuns: new Set(), + entry: assign(({ pendingQueryRuns }) => { + return { + pendingQueryRuns: new Set(), + currentlyHandledPendingQueryRuns: pendingQueryRuns, + } }), invoke: { id: `calculating-dirty-queries`, src: `calculateDirtyQueries`, onDone: { target: `runningStaticQueries`, - actions: [`assignDirtyQueries`], + actions: [ + `assignDirtyQueries`, + `clearCurrentlyHandledPendingQueryRuns`, + ], }, }, }, diff --git a/packages/gatsby/src/state-machines/query-running/types.ts b/packages/gatsby/src/state-machines/query-running/types.ts index 269b59df779c3..e7ee8420ed7bd 100644 --- a/packages/gatsby/src/state-machines/query-running/types.ts +++ b/packages/gatsby/src/state-machines/query-running/types.ts @@ -23,4 +23,5 @@ export interface IQueryRunningContext { websocketManager?: WebsocketManager filesDirty?: boolean pendingQueryRuns?: Set + currentlyHandledPendingQueryRuns?: Set }