From 3032a1b07dbcfed292b7f32f12eef485ea2258a0 Mon Sep 17 00:00:00 2001 From: Lennart Date: Thu, 17 Nov 2022 08:59:24 +0100 Subject: [PATCH] fix(gatsby): Use xstate `predictableActionArguments` & update to 4.34 (#36342) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update version and fix types * yolo add option * Work around removal of meta.state * Refactor `meta.state` access in `gatsby-source-filesystem` (#36355) Co-authored-by: Lennart * fix ts-ignore * Upgrade XState to the latest 4.33.3 (#36451) * update to latest xstate * Use `pendingQueryRuns` available on the event (#36393) * Revert "Use `pendingQueryRuns` available on the event (#36393)" This reverts commit 9460dd35900d51e45d159cc9d9f153df2f938fe6. Co-authored-by: tyhopp Co-authored-by: Mateusz BurzyƄski Co-authored-by: Ty Hopp --- packages/gatsby-source-filesystem/package.json | 2 +- packages/gatsby-source-filesystem/src/gatsby-node.js | 11 ++++++++--- packages/gatsby/package.json | 2 +- .../gatsby/src/state-machines/data-layer/index.ts | 3 +++ packages/gatsby/src/state-machines/develop/index.ts | 1 + .../gatsby/src/state-machines/query-running/index.ts | 1 + packages/gatsby/src/state-machines/waiting/index.ts | 1 + yarn.lock | 8 ++++---- 8 files changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/gatsby-source-filesystem/package.json b/packages/gatsby-source-filesystem/package.json index 0071a3228fcb5..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.32.1" + "xstate": "^4.34.0" }, "devDependencies": { "@babel/cli": "^7.15.4", diff --git a/packages/gatsby-source-filesystem/src/gatsby-node.js b/packages/gatsby-source-filesystem/src/gatsby-node.js index 8a2d70003962d..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 { Machine, interpret } = require(`xstate`) +const { createMachine, interpret, assign } = require(`xstate`) const { createFileNode } = require(`./create-file-node`) const { ERROR_MAP } = require(`./error-utils`) @@ -61,13 +61,17 @@ const createFSMachine = ( } const log = expr => (ctx, action, meta) => { - if (meta.state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) { + if (ctx.bootstrapped) { reporter.info(expr(ctx, action, meta)) } } - const fsMachine = Machine( + const fsMachine = createMachine( { + predictableActionArguments: true, + context: { + bootstrapped: false, + }, id: `fs`, type: `parallel`, states: { @@ -81,6 +85,7 @@ const createFSMachine = ( }, BOOTSTRAPPED: { type: `final`, + entry: assign({ bootstrapped: true }), }, }, }, diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index aab6464e48560..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.32.1", + "xstate": "^4.34.0", "yaml-loader": "^0.6.0" }, "devDependencies": { 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 4d2aaef80ca96..5b791316adfdc 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: { diff --git a/yarn.lock b/yarn.lock index 468aa5b2dd177..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.32.1: - version "4.32.1" - resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.32.1.tgz#1a09c808a66072938861a3b4acc5b38460244b70" - integrity sha512-QYUd+3GkXZ8i6qdixnOn28bL3EvA++LONYL/EMWwKlFSh/hiLndJ8YTnz77FDs+JUXcwU7NZJg7qoezoRHc4GQ== +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"