From 3a043c1bb7b6f5ade97a5408f0bc2c55944bff77 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 21 Jan 2021 14:57:03 +0100 Subject: [PATCH 01/11] update shopify plugin readme --- packages/gatsby-source-shopify/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-shopify/README.md b/packages/gatsby-source-shopify/README.md index 3c350ddabb08f..aa2b82d279d75 100644 --- a/packages/gatsby-source-shopify/README.md +++ b/packages/gatsby-source-shopify/README.md @@ -472,8 +472,8 @@ To learn more about image processing, check the documentation of ```js const path = require("path") -exports.createPages = async ({ graphql, boundActionCreators }) => { - const { createPage } = boundActionCreators +exports.createPages = async ({ graphql, actions }) => { + const { createPage } = actions const pages = await graphql(` { From 92e3231c193dc97c1e2f3186a84d791b05f02bdc Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 21 Jan 2021 14:57:24 +0100 Subject: [PATCH 02/11] update gatsby-source-npm-package-search --- .../src/__tests__/gatsby-node.js | 12 ++++++------ .../src/gatsby-node.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/gatsby-source-npm-package-search/src/__tests__/gatsby-node.js b/packages/gatsby-source-npm-package-search/src/__tests__/gatsby-node.js index b7ee677105c92..a20045a040e65 100644 --- a/packages/gatsby-source-npm-package-search/src/__tests__/gatsby-node.js +++ b/packages/gatsby-source-npm-package-search/src/__tests__/gatsby-node.js @@ -7,12 +7,12 @@ jest.mock(`got`) describe(`gatsby-source-npm-package-search`, () => { describe(`sourceNodes`, () => { - let boundActionCreators + let actions let createNodeId let createContentDigest beforeEach(async () => { - boundActionCreators = { + actions = { createNode: jest.fn(), } createNodeId = jest.fn(id => id) @@ -29,7 +29,7 @@ describe(`gatsby-source-npm-package-search`, () => { ]) await sourceNodes( { - boundActionCreators, + actions, createNodeId, createContentDigest, }, @@ -44,11 +44,11 @@ describe(`gatsby-source-npm-package-search`, () => { }) it(`should create a package node for each search hit`, () => { - expect(boundActionCreators.createNode.mock.calls[0]).toMatchSnapshot() + expect(actions.createNode.mock.calls[0]).toMatchSnapshot() }) it(`should create readme node for each search hit`, () => { - expect(boundActionCreators.createNode.mock.calls[1]).toMatchSnapshot() + expect(actions.createNode.mock.calls[1]).toMatchSnapshot() }) }) @@ -62,7 +62,7 @@ describe(`gatsby-source-npm-package-search`, () => { ]) await sourceNodes( { - boundActionCreators, + actions, createNodeId, createContentDigest, }, diff --git a/packages/gatsby-source-npm-package-search/src/gatsby-node.js b/packages/gatsby-source-npm-package-search/src/gatsby-node.js index a888b1e76a11b..6a238d0102af1 100644 --- a/packages/gatsby-source-npm-package-search/src/gatsby-node.js +++ b/packages/gatsby-source-npm-package-search/src/gatsby-node.js @@ -73,10 +73,10 @@ exports.createSchemaCustomization = ({ actions }) => { } exports.sourceNodes = async ( - { boundActionCreators, createNodeId, createContentDigest }, + { actions, createNodeId, createContentDigest }, { keywords } ) => { - const { createNode } = boundActionCreators + const { createNode } = actions const buildFilter = keywords.map(keyword => `keywords:${keyword}`) From 504dc7e1d717077a73ec6259bb3c5e07853a17eb Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 21 Jan 2021 15:08:12 +0100 Subject: [PATCH 03/11] rename internal usage in gatsby-plugin-sharp --- .../src/__tests__/index.js | 98 +++++++++---------- .../src/__tests__/scheduler.js | 16 +-- .../gatsby-plugin-sharp/src/gatsby-node.js | 4 +- packages/gatsby-plugin-sharp/src/index.js | 16 +-- packages/gatsby-plugin-sharp/src/scheduler.js | 10 +- 5 files changed, 69 insertions(+), 75 deletions(-) diff --git a/packages/gatsby-plugin-sharp/src/__tests__/index.js b/packages/gatsby-plugin-sharp/src/__tests__/index.js index d077d78d14533..98e67a3f24f62 100644 --- a/packages/gatsby-plugin-sharp/src/__tests__/index.js +++ b/packages/gatsby-plugin-sharp/src/__tests__/index.js @@ -9,7 +9,7 @@ jest.mock(`async/queue`, () => () => { }) jest.mock(`gatsby/dist/redux/actions`, () => { return { - boundActionCreators: { + actions: { createJobV2: jest.fn().mockReturnValue(Promise.resolve()), }, } @@ -30,7 +30,7 @@ const { getImageSize, getImageSizeAsync, stats, - setBoundActionCreators, + setActions, } = require(`../`) const { @@ -73,15 +73,13 @@ describe(`gatsby-plugin-sharp`, () => { describe(`queueImageResizing`, () => { ;[`createJob`, `createJobV2`].forEach(api => { describe(`with ${api}`, () => { - let boundActionCreators + let actions beforeEach(() => { - boundActionCreators = {} + actions = {} if (api === `createJobV2`) { - boundActionCreators.createJobV2 = jest - .fn() - .mockReturnValue(Promise.resolve()) + actions.createJobV2 = jest.fn().mockReturnValue(Promise.resolve()) } - setBoundActionCreators(boundActionCreators) + setActions(actions) scheduleJob.mockClear() }) @@ -96,8 +94,8 @@ describe(`gatsby-plugin-sharp`, () => { // We expect value to be rounded to 1 expect(result.height).toBe(1) if (api === `createJobV2`) { - expect(boundActionCreators.createJobV2).toHaveBeenCalledTimes(1) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toHaveBeenCalledTimes(1) + expect(actions.createJobV2).toMatchSnapshot() } else { expect(scheduleJob).toHaveBeenCalledTimes(1) expect(scheduleJob).toMatchSnapshot() @@ -126,8 +124,8 @@ describe(`gatsby-plugin-sharp`, () => { expect(testName.match(/[!@#$^&," ]/)).not.toBe(false) expect(queueResultName.match(/[!@#$^&," ]/)).not.toBe(true) if (api === `createJobV2`) { - expect(boundActionCreators.createJobV2).toHaveBeenCalledTimes(1) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toHaveBeenCalledTimes(1) + expect(actions.createJobV2).toMatchSnapshot() } else { expect(scheduleJob).toHaveBeenCalledTimes(1) expect(scheduleJob).toMatchSnapshot() @@ -150,48 +148,46 @@ describe(`gatsby-plugin-sharp`, () => { it(`should return the same result when using createJob as createJobV2`, async () => { scheduleJob.mockClear() - const boundActionCreators = { + const actions = { createJobV2: jest.fn(() => Promise.resolve()), } - setBoundActionCreators(boundActionCreators) + setActions(actions) const resultV2 = await queueImageResizing({ file: getFileObject(path.join(__dirname, `images/144-density.png`)), args: { width: 3 }, }) - setBoundActionCreators({}) + setActions({}) const result = await queueImageResizing({ file: getFileObject(path.join(__dirname, `images/144-density.png`)), args: { width: 3 }, }) - expect(boundActionCreators.createJobV2).toHaveBeenCalledTimes(1) + expect(actions.createJobV2).toHaveBeenCalledTimes(1) expect(scheduleJob).toHaveBeenCalledTimes(1) expect(result).toStrictEqual(resultV2) }) }) describe(`fluid`, () => { - let boundActionCreators = {} + let actions = {} beforeEach(() => { - boundActionCreators.createJobV2 = jest - .fn() - .mockReturnValue(Promise.resolve()) - setBoundActionCreators(boundActionCreators) + actions.createJobV2 = jest.fn().mockReturnValue(Promise.resolve()) + setActions(actions) scheduleJob.mockClear() }) it(`includes responsive image properties, e.g. sizes, srcset, etc.`, async () => { const result = await fluid({ file }) - expect(boundActionCreators.createJobV2).toHaveBeenCalledTimes(1) + expect(actions.createJobV2).toHaveBeenCalledTimes(1) expect(result).toMatchSnapshot() }) it(`includes responsive image properties, e.g. sizes, srcset, etc. with the createJob api`, async () => { - setBoundActionCreators({}) + setActions({}) const result = await fluid({ file }) - expect(boundActionCreators.createJobV2).not.toHaveBeenCalled() + expect(actions.createJobV2).not.toHaveBeenCalled() expect(scheduleJob).toHaveBeenCalledTimes(1) expect(result).toMatchSnapshot() }) @@ -199,12 +195,12 @@ describe(`gatsby-plugin-sharp`, () => { it(`should give the same result with createJob as with createJobV2`, async () => { const resultV2 = await fluid({ file }) - setBoundActionCreators({}) + setActions({}) const result = await fluid({ file }) - expect(boundActionCreators.createJobV2).toHaveBeenCalledTimes(1) + expect(actions.createJobV2).toHaveBeenCalledTimes(1) expect(scheduleJob).toHaveBeenCalledTimes(1) expect(result).toStrictEqual(resultV2) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) it(`adds pathPrefix if defined`, async () => { @@ -218,7 +214,7 @@ describe(`gatsby-plugin-sharp`, () => { expect(result.src.indexOf(pathPrefix)).toBe(0) expect(result.srcSet.indexOf(pathPrefix)).toBe(0) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) it(`keeps original file name`, async () => { @@ -228,7 +224,7 @@ describe(`gatsby-plugin-sharp`, () => { expect(path.parse(result.src).name).toBe(file.name) expect(path.parse(result.srcSet).name).toBe(file.name) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) it(`does not change the arguments object it is given`, async () => { @@ -239,7 +235,7 @@ describe(`gatsby-plugin-sharp`, () => { }) expect(args).toEqual({ maxWidth: 400 }) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) it(`infers the maxWidth if only maxHeight is given`, async () => { @@ -250,7 +246,7 @@ describe(`gatsby-plugin-sharp`, () => { }) expect(result.presentationWidth).toEqual(41) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) it(`calculate height based on width when maxWidth & maxHeight are present`, async () => { @@ -287,13 +283,13 @@ describe(`gatsby-plugin-sharp`, () => { ) for (const testCase of testsCases) { - boundActionCreators.createJobV2.mockClear() + actions.createJobV2.mockClear() const result = await fluid({ file: fileObject, args: testCase.args, }) - expect(boundActionCreators.createJobV2.mock.calls).toMatchSnapshot() + expect(actions.createJobV2.mock.calls).toMatchSnapshot() expect(result.presentationWidth).toEqual(testCase.result[0]) expect(result.presentationHeight).toEqual(testCase.result[1]) } @@ -307,7 +303,7 @@ describe(`gatsby-plugin-sharp`, () => { }) await expect(result).rejects.toThrow() - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) it(`accepts srcSet breakpoints`, async () => { @@ -327,7 +323,7 @@ describe(`gatsby-plugin-sharp`, () => { const actual = findAllBreakpoints(result.srcSet) // should contain all requested sizes as well as the original size expect(actual).toEqual(expect.arrayContaining(expected)) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) it(`should throw on srcSet breakpoints less than 1`, async () => { @@ -339,7 +335,7 @@ describe(`gatsby-plugin-sharp`, () => { }) await expect(result).rejects.toThrow() - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) it(`ensure maxWidth is in srcSet breakpoints`, async () => { @@ -355,7 +351,7 @@ describe(`gatsby-plugin-sharp`, () => { }) expect(result.srcSet).toEqual(expect.stringContaining(`${maxWidth}w`)) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) it(`reject any breakpoints larger than the original width`, async () => { @@ -390,7 +386,7 @@ describe(`gatsby-plugin-sharp`, () => { expect(actual).toEqual(expect.arrayContaining(expected)) // should contain no other sizes expect(actual.length).toEqual(expected.length) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) it(`prevents duplicate breakpoints`, async () => { @@ -411,34 +407,32 @@ describe(`gatsby-plugin-sharp`, () => { const actual = findAllBreakpoints(result.srcSet) expect(actual).toEqual(expect.arrayContaining(expected)) expect(actual.length).toEqual(expected.length) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) }) describe(`fixed`, () => { - let boundActionCreators = {} + let actions = {} beforeEach(() => { - boundActionCreators.createJobV2 = jest - .fn() - .mockReturnValue(Promise.resolve()) - setBoundActionCreators(boundActionCreators) + actions.createJobV2 = jest.fn().mockReturnValue(Promise.resolve()) + setActions(actions) scheduleJob.mockClear() console.warn = jest.fn() }) it(`should give the same result with createJob as with createJobV2`, async () => { - const boundActionCreators = { + const actions = { createJobV2: jest.fn(() => Promise.resolve()), } - setBoundActionCreators(boundActionCreators) + setActions(actions) const resultV2 = await fixed({ file, args: { width: 1 } }) - setBoundActionCreators({}) + setActions({}) const result = await fixed({ file, args: { width: 1 } }) - expect(boundActionCreators.createJobV2).toHaveBeenCalledTimes(1) + expect(actions.createJobV2).toHaveBeenCalledTimes(1) expect(scheduleJob).toHaveBeenCalledTimes(1) expect(result).toStrictEqual(resultV2) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) it(`does not warn when the requested width is equal to the image width`, async () => { @@ -451,7 +445,7 @@ describe(`gatsby-plugin-sharp`, () => { expect(result.width).toEqual(1) expect(console.warn).toHaveBeenCalledTimes(0) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) it(`warns when the requested width is greater than the image width`, async () => { @@ -465,7 +459,7 @@ describe(`gatsby-plugin-sharp`, () => { expect(result.width).toEqual(width) expect(console.warn).toHaveBeenCalledTimes(1) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) it(`correctly infers the width when only the height is given`, async () => { @@ -477,7 +471,7 @@ describe(`gatsby-plugin-sharp`, () => { }) expect(result.width).toEqual(21) - expect(boundActionCreators.createJobV2).toMatchSnapshot() + expect(actions.createJobV2).toMatchSnapshot() }) }) diff --git a/packages/gatsby-plugin-sharp/src/__tests__/scheduler.js b/packages/gatsby-plugin-sharp/src/__tests__/scheduler.js index 0e783be036927..a2b0fcaea4931 100644 --- a/packages/gatsby-plugin-sharp/src/__tests__/scheduler.js +++ b/packages/gatsby-plugin-sharp/src/__tests__/scheduler.js @@ -10,11 +10,11 @@ const fs = require(`fs-extra`) const workerMock = require(`../gatsby-worker`).IMAGE_PROCESSING describe(`scheduler`, () => { - let boundActionCreators = {} + let actions = {} let scheduler beforeEach(() => { workerMock.mockReset() - boundActionCreators = { + actions = { createJob: jest.fn(), endJob: jest.fn(), } @@ -43,7 +43,7 @@ describe(`scheduler`, () => { pluginOptions: {}, }, } - await scheduleJob(job, boundActionCreators) + await scheduleJob(job, actions) expect(workerMock).toHaveBeenCalledWith( expect.objectContaining({ @@ -79,7 +79,7 @@ describe(`scheduler`, () => { pluginOptions: {}, }, }, - boundActionCreators + actions ) } catch (err) { expect(err).toEqual(`failed transform`) @@ -104,7 +104,7 @@ describe(`scheduler`, () => { pluginOptions: {}, }, } - await scheduleJob(job, boundActionCreators) + await scheduleJob(job, actions) expect(workerMock).not.toHaveBeenCalled() fs.existsSync = orignalSync @@ -126,8 +126,8 @@ describe(`scheduler`, () => { pluginOptions: {}, }, } - const jobPromise = scheduleJob(job, boundActionCreators) - const job2Promise = scheduleJob(job, boundActionCreators) + const jobPromise = scheduleJob(job, actions) + const job2Promise = scheduleJob(job, actions) expect(jobPromise).toStrictEqual(job2Promise) await Promise.all([jobPromise, job2Promise]) @@ -165,7 +165,7 @@ describe(`scheduler`, () => { }, } - await scheduleJob(job, boundActionCreators) + await scheduleJob(job, actions) expect(got.post).toHaveBeenCalledWith( process.env.GATSBY_CLOUD_IMAGE_SERVICE_URL, diff --git a/packages/gatsby-plugin-sharp/src/gatsby-node.js b/packages/gatsby-plugin-sharp/src/gatsby-node.js index c8230631abfb1..6d695de40c7d9 100644 --- a/packages/gatsby-plugin-sharp/src/gatsby-node.js +++ b/packages/gatsby-plugin-sharp/src/gatsby-node.js @@ -1,5 +1,5 @@ const { - setBoundActionCreators, + setActions, // queue: jobQueue, // reportError, _unstable_createJob, @@ -123,7 +123,7 @@ exports.onPreBootstrap = async ( { actions, emitter, reporter, cache, store }, pluginOptions ) => { - setBoundActionCreators(actions) + setActions(actions) setPluginOptions(pluginOptions) // below is a hack / hot fix for confusing progress bar behaviour diff --git a/packages/gatsby-plugin-sharp/src/index.js b/packages/gatsby-plugin-sharp/src/index.js index 3536017a7b447..7aaec238cda88 100644 --- a/packages/gatsby-plugin-sharp/src/index.js +++ b/packages/gatsby-plugin-sharp/src/index.js @@ -66,14 +66,14 @@ const getImageSize = file => { } } -// Bound action creators should be set when passed to onPreInit in gatsby-node. +// Actions should be set when passed to onPreInit in gatsby-node. // ** It is NOT safe to just directly require the gatsby module **. // There is no guarantee that the module resolved is the module executing! // This can occur in mono repos depending on how dependencies have been hoisted. // The direct require has been left only to avoid breaking changes. -let boundActionCreators -exports.setBoundActionCreators = actions => { - boundActionCreators = actions +let actions +exports.setActions = _actions => { + actions = _actions } exports.generateImageData = generateImageData @@ -125,7 +125,7 @@ function prepareQueue({ file, args }) { } function createJob(job, { reporter }) { - if (!boundActionCreators) { + if (!actions) { reporter.panic( `Gatsby-plugin-sharp wasn't setup correctly in gatsby-config.js. Make sure you add it to the plugins array.` ) @@ -139,10 +139,10 @@ function createJob(job, { reporter }) { // entire closure would keep duplicate job in memory until // initial job finish. let promise = null - if (boundActionCreators.createJobV2) { - promise = boundActionCreators.createJobV2(job) + if (actions.createJobV2) { + promise = actions.createJobV2(job) } else { - promise = scheduleJob(job, boundActionCreators, reporter) + promise = scheduleJob(job, actions, reporter) } promise.catch(err => { diff --git a/packages/gatsby-plugin-sharp/src/scheduler.js b/packages/gatsby-plugin-sharp/src/scheduler.js index 583a064905e67..7dbf23f5b7ce0 100644 --- a/packages/gatsby-plugin-sharp/src/scheduler.js +++ b/packages/gatsby-plugin-sharp/src/scheduler.js @@ -6,18 +6,18 @@ const { createContentDigest } = require(`gatsby-core-utils`) const worker = require(`./gatsby-worker`) const { createOrGetProgressBar } = require(`./utils`) -const processImages = async (jobId, job, boundActionCreators) => { +const processImages = async (jobId, job, actions) => { try { await worker.IMAGE_PROCESSING(job) } catch (err) { throw err } finally { - boundActionCreators.endJob({ id: jobId }, { name: `gatsby-plugin-sharp` }) + actions.endJob({ id: jobId }, { name: `gatsby-plugin-sharp` }) } } const jobsInFlight = new Map() -const scheduleJob = async (job, boundActionCreators, reporter) => { +const scheduleJob = async (job, actions, reporter) => { const inputPaths = job.inputPaths.filter( inputPath => !fs.existsSync(path.join(job.outputDir, inputPath)) ) @@ -74,7 +74,7 @@ const scheduleJob = async (job, boundActionCreators, reporter) => { } const jobId = uuidv4() - boundActionCreators.createJob( + actions.createJob( { id: jobId, description: `processing image ${job.inputPaths[0]}`, @@ -89,7 +89,7 @@ const scheduleJob = async (job, boundActionCreators, reporter) => { const promise = new Promise((resolve, reject) => { setImmediate(() => { - processImages(jobId, convertedJob, boundActionCreators).then(result => { + processImages(jobId, convertedJob, actions).then(result => { progressBar.tick(transformsCount) resolve(result) }, reject) From 1cbd17c0b2e9c647c7444dc21f5f76643d8f774c Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 21 Jan 2021 16:03:43 +0100 Subject: [PATCH 04/11] remove from gatsby package --- packages/gatsby/index.d.ts | 6 ------ packages/gatsby/src/redux/actions/index.ts | 7 ------- packages/gatsby/src/utils/api-node-helpers-docs.js | 10 ---------- .../gatsby/src/utils/print-deprecation-warnings.ts | 7 +------ 4 files changed, 1 insertion(+), 29 deletions(-) diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index a5c121564806d..257b6d0ae2cc8 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -958,12 +958,6 @@ export interface NodePluginArgs { */ pathPrefix: string - /** - * Collection of functions used to programmatically modify Gatsby’s internal state. - * @deprecated Will be removed in gatsby 3.0. Use `actions` instead - */ - boundActionCreators: Actions - /** * Collection of functions used to programmatically modify Gatsby’s internal state. */ diff --git a/packages/gatsby/src/redux/actions/index.ts b/packages/gatsby/src/redux/actions/index.ts index c3b86fb8eda3c..b5354f4e62379 100644 --- a/packages/gatsby/src/redux/actions/index.ts +++ b/packages/gatsby/src/redux/actions/index.ts @@ -1,7 +1,3 @@ -import { bindActionCreators } from "redux" - -import { store } from ".." - import * as internalActions from "./internal" import { actions as publicActions } from "./public" import { @@ -15,9 +11,6 @@ export const actions = { ...restrictedActions, } -// Deprecated, remove in v3 -export const boundActionCreators = bindActionCreators(actions, store.dispatch) - export const restrictedActionsAvailableInAPI = availableActionsByAPI export { internalActions, publicActions, restrictedActions } diff --git a/packages/gatsby/src/utils/api-node-helpers-docs.js b/packages/gatsby/src/utils/api-node-helpers-docs.js index 3ea45a1ea0557..6e8568e69c576 100644 --- a/packages/gatsby/src/utils/api-node-helpers-docs.js +++ b/packages/gatsby/src/utils/api-node-helpers-docs.js @@ -161,16 +161,6 @@ module.exports.cache = true; */ module.exports.createContentDigest = true; -/** - * Collection of functions used to programmatically modify Gatsby’s internal state. - * - * See [`actions`](/docs/actions/) reference. - * @type {Actions} - * @deprecated Will be removed in gatsby 3.0. Use [actions](#actions) - * instead. - */ -module.exports.boundActionCreators = true; - /** * Collection of functions used to programmatically modify Gatsby’s internal state. * diff --git a/packages/gatsby/src/utils/print-deprecation-warnings.ts b/packages/gatsby/src/utils/print-deprecation-warnings.ts index c133c05e2e971..94bd1d6fc1fd2 100644 --- a/packages/gatsby/src/utils/print-deprecation-warnings.ts +++ b/packages/gatsby/src/utils/print-deprecation-warnings.ts @@ -3,19 +3,14 @@ import glob from "glob" import chalk from "chalk" export function printDeprecationWarnings(): void { - const deprecatedApis = [`boundActionCreators`, `pathContext`] + const deprecatedApis = [`pathContext`] const fixMap = { - boundActionCreators: { - newName: `actions`, - docsLink: `https://gatsby.dev/boundActionCreators`, - }, pathContext: { newName: `pageContext`, docsLink: `https://gatsby.dev/pathContext`, }, } const deprecatedLocations: Record> = { - boundActionCreators: [], pathContext: [], } From 54065de13ece9d58f94e09064885887e731548d4 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Fri, 22 Jan 2021 10:28:16 +0100 Subject: [PATCH 05/11] update imports --- packages/gatsby/src/commands/build.ts | 8 +++----- .../internal-data-bridge/gatsby-node.js | 4 ++-- .../src/internal-plugins/prod-404/gatsby-node.js | 4 ++-- packages/gatsby/src/query/__tests__/data-tracking.js | 6 +++--- packages/gatsby/src/query/file-parser.js | 12 ++++++------ packages/gatsby/src/query/query-compiler.js | 5 ++--- packages/gatsby/src/query/query-runner.ts | 8 ++++---- packages/gatsby/src/query/query-watcher.ts | 6 +++--- packages/gatsby/src/redux/actions/internal.ts | 8 +++++++- packages/gatsby/src/services/create-pages.ts | 4 ++-- packages/gatsby/src/services/post-bootstrap.ts | 4 ++-- .../gatsby/src/state-machines/develop/actions.ts | 10 ++++------ packages/gatsby/src/utils/changed-pages.ts | 4 ++-- packages/gatsby/src/utils/dev-ssr/render-dev-html.ts | 4 ++-- packages/gatsby/src/utils/source-nodes.ts | 4 ++-- 15 files changed, 46 insertions(+), 45 deletions(-) diff --git a/packages/gatsby/src/commands/build.ts b/packages/gatsby/src/commands/build.ts index a222cee30c453..02a2de45e29ba 100644 --- a/packages/gatsby/src/commands/build.ts +++ b/packages/gatsby/src/commands/build.ts @@ -24,7 +24,7 @@ import { showSevenDayFeedbackRequest, } from "../utils/feedback" import * as buildUtils from "./build-utils" -import { boundActionCreators } from "../redux/actions" +import { actions } from "../redux/actions" import { waitUntilAllJobsComplete } from "../utils/wait-until-jobs-complete" import { IProgram, Stage } from "./types" import { PackageJson } from "../.." @@ -178,9 +178,7 @@ module.exports = async function build(program: IBuildArgs): Promise { if (cachedPageData) { cachedPageData.forEach((_value, key) => { if (!pages.has(key)) { - boundActionCreators.removePageData({ - id: key, - }) + actions.removePageData(key) } }) } @@ -201,7 +199,7 @@ module.exports = async function build(program: IBuildArgs): Promise { }) } - boundActionCreators.setProgramStatus(`BOOTSTRAP_QUERY_RUNNING_FINISHED`) + actions.setProgramStatus(`BOOTSTRAP_QUERY_RUNNING_FINISHED`) await db.saveState() diff --git a/packages/gatsby/src/internal-plugins/internal-data-bridge/gatsby-node.js b/packages/gatsby/src/internal-plugins/internal-data-bridge/gatsby-node.js index 260e5a350dac5..4b825a2ee5faa 100644 --- a/packages/gatsby/src/internal-plugins/internal-data-bridge/gatsby-node.js +++ b/packages/gatsby/src/internal-plugins/internal-data-bridge/gatsby-node.js @@ -4,7 +4,7 @@ const systemPath = require(`path`) const _ = require(`lodash`) const { emitter } = require(`../../redux`) -const { boundActionCreators } = require(`../../redux/actions`) +const { actions } = require(`../../redux/actions`) const { getNode } = require(`../../redux/nodes`) function transformPackageJson(json) { @@ -197,5 +197,5 @@ exports.onCreatePage = ({ createContentDigest, page, actions }) => { emitter.on(`DELETE_PAGE`, action => { const nodeId = createPageId(action.payload.path) const node = getNode(nodeId) - boundActionCreators.deleteNode({ node }) + actions.deleteNode({ node }) }) diff --git a/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js b/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js index 73751b8d419ec..7ac5f4abb4bd8 100644 --- a/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js +++ b/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js @@ -1,5 +1,5 @@ const { emitter } = require(`../../redux`) -const { boundActionCreators } = require(`../../redux/actions`) +const { actions } = require(`../../redux/actions`) const PROD_404_PAGE_PATH = `/404.html` @@ -19,7 +19,7 @@ exports.onCreatePage = ({ page, store, actions }) => { emitter.on(`DELETE_PAGE`, action => { if (page404 && action.payload.path === page404.path) { - boundActionCreators.deletePage({ + actions.deletePage({ ...page404, path: PROD_404_PAGE_PATH, }) diff --git a/packages/gatsby/src/query/__tests__/data-tracking.js b/packages/gatsby/src/query/__tests__/data-tracking.js index 4cf4f99410b65..b4bfd3098c518 100644 --- a/packages/gatsby/src/query/__tests__/data-tracking.js +++ b/packages/gatsby/src/query/__tests__/data-tracking.js @@ -153,11 +153,11 @@ const setup = async ({ restart = isFirstRun, clearCache = false } = {}) => { const { saveState } = require(`../../db`) const reporter = require(`gatsby-cli/lib/reporter`) const { queryRunner } = require(`../query-runner`) - const { boundActionCreators } = require(`../../redux/actions`) - const doubleBoundActionCreators = Object.keys(boundActionCreators).reduce( + const { actions } = require(`../../redux/actions`) + const doubleBoundActionCreators = Object.keys(actions).reduce( (acc, actionName) => { acc[actionName] = (...args) => - boundActionCreators[actionName](...args, { + actions[actionName](...args, { name: `gatsby-source-test`, version: `1.0.0`, }) diff --git a/packages/gatsby/src/query/file-parser.js b/packages/gatsby/src/query/file-parser.js index 318ac44678dfc..ec1f61d1774a7 100644 --- a/packages/gatsby/src/query/file-parser.js +++ b/packages/gatsby/src/query/file-parser.js @@ -21,7 +21,7 @@ import { babelParseToAst } from "../utils/babel-parse-to-ast" import { codeFrameColumns } from "@babel/code-frame" const apiRunnerNode = require(`../utils/api-runner-node`) -const { boundActionCreators } = require(`../redux/actions`) +const { actions } = require(`../redux/actions`) import { locInGraphQlToLocInFile } from "./error-parser" /** * Add autogenerated query name if it wasn't defined by user. @@ -103,7 +103,7 @@ async function parseToAst(filePath, fileStr, { parentSpan, addError } = {}) { filePath, }, }) - boundActionCreators.queryExtractionGraphQLError({ + actions.queryExtractionGraphQLError({ componentPath: filePath, }) @@ -113,7 +113,7 @@ async function parseToAst(filePath, fileStr, { parentSpan, addError } = {}) { try { ast = babelParseToAst(fileStr, filePath) } catch (error) { - boundActionCreators.queryExtractionBabelError({ + actions.queryExtractionBabelError({ componentPath: filePath, error, }) @@ -410,7 +410,7 @@ export default class FileParser { error: err, }) - boundActionCreators.queryExtractionGraphQLError({ + actions.queryExtractionGraphQLError({ componentPath: file, }) return null @@ -438,7 +438,7 @@ export default class FileParser { // This can mean there is none or there was a babel error when // we tried to extract the graphql AST. if (astDefinitions.length > 0) { - boundActionCreators.queryExtractedBabelSuccess({ + actions.queryExtractedBabelSuccess({ componentPath: file, }) } @@ -514,7 +514,7 @@ export default class FileParser { filePath: file, }) - boundActionCreators.queryExtractionGraphQLError({ + actions.queryExtractionGraphQLError({ componentPath: file, }) return null diff --git a/packages/gatsby/src/query/query-compiler.js b/packages/gatsby/src/query/query-compiler.js index e7cd4361a7c15..52eeacae0ef79 100644 --- a/packages/gatsby/src/query/query-compiler.js +++ b/packages/gatsby/src/query/query-compiler.js @@ -30,8 +30,7 @@ const { import { getGatsbyDependents } from "../utils/gatsby-dependents" const { store } = require(`../redux`) -import * as actions from "../redux/actions/internal" -import { boundActionCreators } from "../redux/actions" +import { actions } from "../redux/actions" import { websocketManager } from "../utils/websocket-manager" const { default: FileParser } = require(`./file-parser`) @@ -175,7 +174,7 @@ export const processQueries = ({ parentSpan ) - boundActionCreators.setGraphQLDefinitions(definitionsByName) + actions.setGraphQLDefinitions(definitionsByName) return processDefinitions({ schema, diff --git a/packages/gatsby/src/query/query-runner.ts b/packages/gatsby/src/query/query-runner.ts index e7f4df890903a..a9dfa5ae8bb87 100644 --- a/packages/gatsby/src/query/query-runner.ts +++ b/packages/gatsby/src/query/query-runner.ts @@ -7,7 +7,7 @@ import { ExecutionResult, GraphQLError } from "graphql" import path from "path" import { store } from "../redux" -import { boundActionCreators } from "../redux/actions" +import { actions } from "../redux/actions" import { getCodeFrame } from "./graphql-errors" import errorParser from "./error-parser" @@ -117,7 +117,7 @@ export async function queryRunner( ): Promise { const { program } = store.getState() - boundActionCreators.queryStart({ + actions.queryStart({ path: queryJob.id, componentPath: queryJob.componentPath, isPage: queryJob.isPage, @@ -199,7 +199,7 @@ export async function queryRunner( } // Broadcast that a page's query has run. - boundActionCreators.pageQueryRun({ + actions.pageQueryRun({ path: queryJob.id, componentPath: queryJob.componentPath, isPage: queryJob.isPage, @@ -210,7 +210,7 @@ export async function queryRunner( process.env.GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES && queryJob.isPage ) { - boundActionCreators.setPageData({ + actions.setPageData({ id: queryJob.id, resultHash, }) diff --git a/packages/gatsby/src/query/query-watcher.ts b/packages/gatsby/src/query/query-watcher.ts index 3c78814fa254e..9a1b31f5e9c1f 100644 --- a/packages/gatsby/src/query/query-watcher.ts +++ b/packages/gatsby/src/query/query-watcher.ts @@ -15,7 +15,7 @@ import path from "path" import { slash } from "gatsby-core-utils" import { store, emitter } from "../redux/" -import { boundActionCreators } from "../redux/actions" +import { actions } from "../redux/actions" import { IGatsbyStaticQueryComponents } from "../redux/types" import queryCompiler from "./query-compiler" import report from "gatsby-cli/lib/reporter" @@ -97,7 +97,7 @@ const handleQuery = ( oldQuery?.hash !== query.hash || oldQuery?.query !== query.text ) { - boundActionCreators.replaceStaticQuery({ + actions.replaceStaticQuery({ name: query.name, componentPath: query.path, id: query.id, @@ -233,7 +233,7 @@ export const updateStateAndRunQueries = async ( const { isStaticQuery = false, text = `` } = queries.get(c.componentPath) || {} - boundActionCreators.queryExtracted({ + actions.queryExtracted({ componentPath: c.componentPath, query: isStaticQuery ? `` : text, }) diff --git a/packages/gatsby/src/redux/actions/internal.ts b/packages/gatsby/src/redux/actions/internal.ts index b6c8c8094ee77..b738a3489578a 100644 --- a/packages/gatsby/src/redux/actions/internal.ts +++ b/packages/gatsby/src/redux/actions/internal.ts @@ -102,7 +102,13 @@ export const apiFinished = ( * @private */ export const replaceStaticQuery = ( - args: any, + args: { + name: string + componentPath: string + id: string + query: string + hash: string + }, plugin: IGatsbyPlugin | null | undefined = null ): IReplaceStaticQueryAction => { return { diff --git a/packages/gatsby/src/services/create-pages.ts b/packages/gatsby/src/services/create-pages.ts index 2ea41f19740be..a3f6e0f1a44da 100644 --- a/packages/gatsby/src/services/create-pages.ts +++ b/packages/gatsby/src/services/create-pages.ts @@ -3,7 +3,7 @@ import apiRunnerNode from "../utils/api-runner-node" import { IDataLayerContext } from "../state-machines/data-layer/types" import { assertStore } from "../utils/assert-store" import { IGatsbyPage } from "../redux/types" -import { boundActionCreators } from "../redux/actions" +import { actions } from "../redux/actions" import { deleteUntouchedPages, findChangedPages } from "../utils/changed-pages" export async function createPages({ @@ -75,7 +75,7 @@ export async function createPages({ ) tim.end() - boundActionCreators.apiFinished({ apiName: `createPages` }) + actions.apiFinished({ apiName: `createPages` }) return { changedPages, diff --git a/packages/gatsby/src/services/post-bootstrap.ts b/packages/gatsby/src/services/post-bootstrap.ts index 30f5e349df8a5..f575ecdf7b9c4 100644 --- a/packages/gatsby/src/services/post-bootstrap.ts +++ b/packages/gatsby/src/services/post-bootstrap.ts @@ -2,7 +2,7 @@ import reporter from "gatsby-cli/lib/reporter" import { emitter } from "../redux" import apiRunnerNode from "../utils/api-runner-node" import { IDataLayerContext } from "../state-machines/data-layer/types" -import { boundActionCreators } from "../redux/actions" +import { actions } from "../redux/actions" export async function postBootstrap({ parentSpan, @@ -22,5 +22,5 @@ export async function postBootstrap({ bootstrap finished - ${process.uptime().toFixed(3)}s `) emitter.emit(`BOOTSTRAP_FINISHED`, {}) - boundActionCreators.setProgramStatus(`BOOTSTRAP_FINISHED`) + actions.setProgramStatus(`BOOTSTRAP_FINISHED`) } diff --git a/packages/gatsby/src/state-machines/develop/actions.ts b/packages/gatsby/src/state-machines/develop/actions.ts index 2f6b071823792..345f4e8246d09 100644 --- a/packages/gatsby/src/state-machines/develop/actions.ts +++ b/packages/gatsby/src/state-machines/develop/actions.ts @@ -7,7 +7,7 @@ import { DoneEventObject, } from "xstate" import { IBuildContext } from "../../services" -import { boundActionCreators } from "../../redux/actions" +import { actions } from "../../redux/actions" import { listenForMutations } from "../../services/listen-for-mutations" import { DataLayerResult } from "../data-layer" import { saveState } from "../../db" @@ -47,9 +47,7 @@ export const assignStoreAndWorkerPool = assign( ) const setQueryRunningFinished = async (): Promise => { - boundActionCreators.setProgramStatus( - ProgramStatus.BOOTSTRAP_QUERY_RUNNING_FINISHED - ) + actions.setProgramStatus(ProgramStatus.BOOTSTRAP_QUERY_RUNNING_FINISHED) } export const markQueryFilesDirty = assign({ @@ -153,8 +151,8 @@ export const panicBecauseOfInfiniteLoop: ActionFunction< > = () => { reporter.panic( reporter.stripIndent(` - Panicking because nodes appear to be being changed every time we run queries. This would cause the site to recompile infinitely. - Check custom resolvers to see if they are unconditionally creating or mutating nodes on every query. + Panicking because nodes appear to be being changed every time we run queries. This would cause the site to recompile infinitely. + Check custom resolvers to see if they are unconditionally creating or mutating nodes on every query. This may happen if they create nodes with a field that is different every time, such as a timestamp or unique id.`) ) } diff --git a/packages/gatsby/src/utils/changed-pages.ts b/packages/gatsby/src/utils/changed-pages.ts index 8d333d5c0dc04..98e2cc0ecd4a2 100644 --- a/packages/gatsby/src/utils/changed-pages.ts +++ b/packages/gatsby/src/utils/changed-pages.ts @@ -1,5 +1,5 @@ -import { boundActionCreators } from "../redux/actions" -const { deletePage } = boundActionCreators +import { actions } from "../redux/actions" +const { deletePage } = actions import { isEqualWith, IsEqualCustomizer } from "lodash" import { IGatsbyPage } from "../redux/types" diff --git a/packages/gatsby/src/utils/dev-ssr/render-dev-html.ts b/packages/gatsby/src/utils/dev-ssr/render-dev-html.ts index d549a530b5e10..fab4f3bc89e9b 100644 --- a/packages/gatsby/src/utils/dev-ssr/render-dev-html.ts +++ b/packages/gatsby/src/utils/dev-ssr/render-dev-html.ts @@ -131,8 +131,8 @@ export const renderDevHTML = ({ isClientOnlyPage = true } - const { boundActionCreators } = require(`../../redux/actions`) - const { createServerVisitedPage } = boundActionCreators + const { actions } = require(`../../redux/actions`) + const { createServerVisitedPage } = actions // Record this page was requested. This will kick off adding its page // component to the ssr bundle (if that's not already happened) createServerVisitedPage(pageObj.componentChunkName) diff --git a/packages/gatsby/src/utils/source-nodes.ts b/packages/gatsby/src/utils/source-nodes.ts index 4345f1e09a7ac..d07a4dfcdaad3 100644 --- a/packages/gatsby/src/utils/source-nodes.ts +++ b/packages/gatsby/src/utils/source-nodes.ts @@ -3,9 +3,9 @@ import { Span } from "opentracing" import apiRunner from "./api-runner-node" import { store } from "../redux" import { getNode, getNodes } from "../redux/nodes" -import { boundActionCreators } from "../redux/actions" +import { actions } from "../redux/actions" import { IGatsbyState } from "../redux/types" -const { deleteNode } = boundActionCreators +const { deleteNode } = actions import { Node } from "../../index" /** From 4621eb7a02ecc3e8b949745a2bfda83dc60a7f8b Mon Sep 17 00:00:00 2001 From: LekoArts Date: Fri, 22 Jan 2021 12:24:25 +0100 Subject: [PATCH 06/11] fix little typo --- packages/gatsby/src/commands/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/src/commands/build.ts b/packages/gatsby/src/commands/build.ts index 02a2de45e29ba..33fd76d052847 100644 --- a/packages/gatsby/src/commands/build.ts +++ b/packages/gatsby/src/commands/build.ts @@ -178,7 +178,7 @@ module.exports = async function build(program: IBuildArgs): Promise { if (cachedPageData) { cachedPageData.forEach((_value, key) => { if (!pages.has(key)) { - actions.removePageData(key) + actions.removePageData({ id: key }) } }) } From 529dc89254600b593750eaa4fbb0f183305dcde2 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 25 Jan 2021 14:33:39 +0100 Subject: [PATCH 07/11] dispatch all actions --- packages/gatsby/src/commands/build.ts | 4 +- .../internal-data-bridge/gatsby-node.js | 4 +- .../internal-plugins/prod-404/gatsby-node.js | 12 +++--- packages/gatsby/src/query/file-parser.js | 43 ++++++++++++------- packages/gatsby/src/query/query-compiler.js | 2 +- packages/gatsby/src/query/query-runner.ts | 34 +++++++++------ packages/gatsby/src/query/query-watcher.ts | 26 ++++++----- packages/gatsby/src/services/create-pages.ts | 3 +- .../gatsby/src/services/post-bootstrap.ts | 4 +- .../src/state-machines/develop/actions.ts | 5 ++- packages/gatsby/src/utils/changed-pages.ts | 3 +- .../src/utils/dev-ssr/render-dev-html.ts | 4 +- packages/gatsby/src/utils/source-nodes.ts | 2 +- 13 files changed, 87 insertions(+), 59 deletions(-) diff --git a/packages/gatsby/src/commands/build.ts b/packages/gatsby/src/commands/build.ts index 33fd76d052847..f8c39235da2c8 100644 --- a/packages/gatsby/src/commands/build.ts +++ b/packages/gatsby/src/commands/build.ts @@ -178,7 +178,7 @@ module.exports = async function build(program: IBuildArgs): Promise { if (cachedPageData) { cachedPageData.forEach((_value, key) => { if (!pages.has(key)) { - actions.removePageData({ id: key }) + store.dispatch(actions.removePageData({ id: key })) } }) } @@ -199,7 +199,7 @@ module.exports = async function build(program: IBuildArgs): Promise { }) } - actions.setProgramStatus(`BOOTSTRAP_QUERY_RUNNING_FINISHED`) + store.dispatch(actions.setProgramStatus(`BOOTSTRAP_QUERY_RUNNING_FINISHED`)) await db.saveState() diff --git a/packages/gatsby/src/internal-plugins/internal-data-bridge/gatsby-node.js b/packages/gatsby/src/internal-plugins/internal-data-bridge/gatsby-node.js index 4b825a2ee5faa..d775170537736 100644 --- a/packages/gatsby/src/internal-plugins/internal-data-bridge/gatsby-node.js +++ b/packages/gatsby/src/internal-plugins/internal-data-bridge/gatsby-node.js @@ -3,7 +3,7 @@ const chokidar = require(`chokidar`) const systemPath = require(`path`) const _ = require(`lodash`) -const { emitter } = require(`../../redux`) +const { emitter, store } = require(`../../redux`) const { actions } = require(`../../redux/actions`) const { getNode } = require(`../../redux/nodes`) @@ -197,5 +197,5 @@ exports.onCreatePage = ({ createContentDigest, page, actions }) => { emitter.on(`DELETE_PAGE`, action => { const nodeId = createPageId(action.payload.path) const node = getNode(nodeId) - actions.deleteNode({ node }) + store.dispatch(actions.deleteNode({ node })) }) diff --git a/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js b/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js index 7ac5f4abb4bd8..e4c77afc30590 100644 --- a/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js +++ b/packages/gatsby/src/internal-plugins/prod-404/gatsby-node.js @@ -1,4 +1,4 @@ -const { emitter } = require(`../../redux`) +const { emitter, store } = require(`../../redux`) const { actions } = require(`../../redux/actions`) const PROD_404_PAGE_PATH = `/404.html` @@ -19,10 +19,12 @@ exports.onCreatePage = ({ page, store, actions }) => { emitter.on(`DELETE_PAGE`, action => { if (page404 && action.payload.path === page404.path) { - actions.deletePage({ - ...page404, - path: PROD_404_PAGE_PATH, - }) + store.dispatch( + actions.deletePage({ + ...page404, + path: PROD_404_PAGE_PATH, + }) + ) page404 = null } }) diff --git a/packages/gatsby/src/query/file-parser.js b/packages/gatsby/src/query/file-parser.js index ec1f61d1774a7..569fe886162d8 100644 --- a/packages/gatsby/src/query/file-parser.js +++ b/packages/gatsby/src/query/file-parser.js @@ -22,6 +22,7 @@ import { codeFrameColumns } from "@babel/code-frame" const apiRunnerNode = require(`../utils/api-runner-node`) const { actions } = require(`../redux/actions`) +const { store } = require(`../redux`) import { locInGraphQlToLocInFile } from "./error-parser" /** * Add autogenerated query name if it wasn't defined by user. @@ -103,9 +104,11 @@ async function parseToAst(filePath, fileStr, { parentSpan, addError } = {}) { filePath, }, }) - actions.queryExtractionGraphQLError({ - componentPath: filePath, - }) + store.dispatch( + actions.queryExtractionGraphQLError({ + componentPath: filePath, + }) + ) return null } @@ -113,10 +116,12 @@ async function parseToAst(filePath, fileStr, { parentSpan, addError } = {}) { try { ast = babelParseToAst(fileStr, filePath) } catch (error) { - actions.queryExtractionBabelError({ - componentPath: filePath, - error, - }) + store.dispatch( + actions.queryExtractionBabelError({ + componentPath: filePath, + error, + }) + ) addError({ id: `85911`, @@ -410,9 +415,11 @@ export default class FileParser { error: err, }) - actions.queryExtractionGraphQLError({ - componentPath: file, - }) + store.dispatch( + actions.queryExtractionGraphQLError({ + componentPath: file, + }) + ) return null } @@ -438,9 +445,11 @@ export default class FileParser { // This can mean there is none or there was a babel error when // we tried to extract the graphql AST. if (astDefinitions.length > 0) { - actions.queryExtractedBabelSuccess({ - componentPath: file, - }) + store.dispatch( + actions.queryExtractedBabelSuccess({ + componentPath: file, + }) + ) } return astDefinitions @@ -514,9 +523,11 @@ export default class FileParser { filePath: file, }) - actions.queryExtractionGraphQLError({ - componentPath: file, - }) + store.dispatch( + actions.queryExtractionGraphQLError({ + componentPath: file, + }) + ) return null } } diff --git a/packages/gatsby/src/query/query-compiler.js b/packages/gatsby/src/query/query-compiler.js index 52eeacae0ef79..503cd5d7e5ab6 100644 --- a/packages/gatsby/src/query/query-compiler.js +++ b/packages/gatsby/src/query/query-compiler.js @@ -174,7 +174,7 @@ export const processQueries = ({ parentSpan ) - actions.setGraphQLDefinitions(definitionsByName) + store.dispatch(actions.setGraphQLDefinitions(definitionsByName)) return processDefinitions({ schema, diff --git a/packages/gatsby/src/query/query-runner.ts b/packages/gatsby/src/query/query-runner.ts index a9dfa5ae8bb87..e706d871d536d 100644 --- a/packages/gatsby/src/query/query-runner.ts +++ b/packages/gatsby/src/query/query-runner.ts @@ -117,11 +117,13 @@ export async function queryRunner( ): Promise { const { program } = store.getState() - actions.queryStart({ - path: queryJob.id, - componentPath: queryJob.componentPath, - isPage: queryJob.isPage, - }) + store.dispatch( + actions.queryStart({ + path: queryJob.id, + componentPath: queryJob.componentPath, + isPage: queryJob.isPage, + }) + ) // Run query let result: IExecutionResult @@ -199,21 +201,25 @@ export async function queryRunner( } // Broadcast that a page's query has run. - actions.pageQueryRun({ - path: queryJob.id, - componentPath: queryJob.componentPath, - isPage: queryJob.isPage, - }) + store.dispatch( + actions.pageQueryRun({ + path: queryJob.id, + componentPath: queryJob.componentPath, + isPage: queryJob.isPage, + }) + ) // Sets pageData to the store, here for easier access to the resultHash if ( process.env.GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES && queryJob.isPage ) { - actions.setPageData({ - id: queryJob.id, - resultHash, - }) + store.dispatch( + actions.setPageData({ + id: queryJob.id, + resultHash, + }) + ) } return result } diff --git a/packages/gatsby/src/query/query-watcher.ts b/packages/gatsby/src/query/query-watcher.ts index 9a1b31f5e9c1f..975448d8fb3ea 100644 --- a/packages/gatsby/src/query/query-watcher.ts +++ b/packages/gatsby/src/query/query-watcher.ts @@ -97,13 +97,15 @@ const handleQuery = ( oldQuery?.hash !== query.hash || oldQuery?.query !== query.text ) { - actions.replaceStaticQuery({ - name: query.name, - componentPath: query.path, - id: query.id, - query: query.text, - hash: query.hash, - }) + store.dispatch( + actions.replaceStaticQuery({ + name: query.name, + componentPath: query.path, + id: query.id, + query: query.text, + hash: query.hash, + }) + ) debug( `Static query in ${component} ${ @@ -233,10 +235,12 @@ export const updateStateAndRunQueries = async ( const { isStaticQuery = false, text = `` } = queries.get(c.componentPath) || {} - actions.queryExtracted({ - componentPath: c.componentPath, - query: isStaticQuery ? `` : text, - }) + store.dispatch( + actions.queryExtracted({ + componentPath: c.componentPath, + query: isStaticQuery ? `` : text, + }) + ) }) let queriesWillNotRun = false diff --git a/packages/gatsby/src/services/create-pages.ts b/packages/gatsby/src/services/create-pages.ts index a3f6e0f1a44da..71e7044e522de 100644 --- a/packages/gatsby/src/services/create-pages.ts +++ b/packages/gatsby/src/services/create-pages.ts @@ -3,6 +3,7 @@ import apiRunnerNode from "../utils/api-runner-node" import { IDataLayerContext } from "../state-machines/data-layer/types" import { assertStore } from "../utils/assert-store" import { IGatsbyPage } from "../redux/types" +import { store as internalStore } from "../redux" import { actions } from "../redux/actions" import { deleteUntouchedPages, findChangedPages } from "../utils/changed-pages" @@ -75,7 +76,7 @@ export async function createPages({ ) tim.end() - actions.apiFinished({ apiName: `createPages` }) + internalStore.dispatch(actions.apiFinished({ apiName: `createPages` })) return { changedPages, diff --git a/packages/gatsby/src/services/post-bootstrap.ts b/packages/gatsby/src/services/post-bootstrap.ts index f575ecdf7b9c4..c770670997838 100644 --- a/packages/gatsby/src/services/post-bootstrap.ts +++ b/packages/gatsby/src/services/post-bootstrap.ts @@ -1,5 +1,5 @@ import reporter from "gatsby-cli/lib/reporter" -import { emitter } from "../redux" +import { emitter, store } from "../redux" import apiRunnerNode from "../utils/api-runner-node" import { IDataLayerContext } from "../state-machines/data-layer/types" import { actions } from "../redux/actions" @@ -22,5 +22,5 @@ export async function postBootstrap({ bootstrap finished - ${process.uptime().toFixed(3)}s `) emitter.emit(`BOOTSTRAP_FINISHED`, {}) - actions.setProgramStatus(`BOOTSTRAP_FINISHED`) + store.dispatch(actions.setProgramStatus(`BOOTSTRAP_FINISHED`)) } diff --git a/packages/gatsby/src/state-machines/develop/actions.ts b/packages/gatsby/src/state-machines/develop/actions.ts index 345f4e8246d09..c26a395d5d044 100644 --- a/packages/gatsby/src/state-machines/develop/actions.ts +++ b/packages/gatsby/src/state-machines/develop/actions.ts @@ -12,6 +12,7 @@ import { listenForMutations } from "../../services/listen-for-mutations" import { DataLayerResult } from "../data-layer" import { saveState } from "../../db" import reporter from "gatsby-cli/lib/reporter" +import { store } from "../../redux" import { ProgramStatus } from "../../redux/types" import { createWebpackWatcher } from "../../services/listen-to-webpack" import { callRealApi } from "../../utils/call-deferred-api" @@ -47,7 +48,9 @@ export const assignStoreAndWorkerPool = assign( ) const setQueryRunningFinished = async (): Promise => { - actions.setProgramStatus(ProgramStatus.BOOTSTRAP_QUERY_RUNNING_FINISHED) + store.dispatch( + actions.setProgramStatus(ProgramStatus.BOOTSTRAP_QUERY_RUNNING_FINISHED) + ) } export const markQueryFilesDirty = assign({ diff --git a/packages/gatsby/src/utils/changed-pages.ts b/packages/gatsby/src/utils/changed-pages.ts index 98e2cc0ecd4a2..b1b888953fa24 100644 --- a/packages/gatsby/src/utils/changed-pages.ts +++ b/packages/gatsby/src/utils/changed-pages.ts @@ -1,4 +1,5 @@ import { actions } from "../redux/actions" +import { store } from "../redux" const { deletePage } = actions import { isEqualWith, IsEqualCustomizer } from "lodash" @@ -17,7 +18,7 @@ export function deleteUntouchedPages( page.updatedAt < timeBeforeApisRan && page.path !== `/404.html` ) { - deletePage(page) + store.dispatch(deletePage(page)) deletedPages.push(page.path, `/page-data${page.path}`) } }) diff --git a/packages/gatsby/src/utils/dev-ssr/render-dev-html.ts b/packages/gatsby/src/utils/dev-ssr/render-dev-html.ts index fab4f3bc89e9b..af654a0aa9c71 100644 --- a/packages/gatsby/src/utils/dev-ssr/render-dev-html.ts +++ b/packages/gatsby/src/utils/dev-ssr/render-dev-html.ts @@ -7,7 +7,7 @@ import { startListener } from "../../bootstrap/requires-writer" import { findPageByPath } from "../find-page-by-path" import { getPageData as getPageDataExperimental } from "../get-page-data" import { getDevSSRWebpack } from "../../commands/build-html" -import { emitter } from "../../redux" +import { emitter, store as internalStore } from "../../redux" const startWorker = (): any => { const newWorker = new JestWorker(require.resolve(`./render-dev-html-child`), { @@ -135,7 +135,7 @@ export const renderDevHTML = ({ const { createServerVisitedPage } = actions // Record this page was requested. This will kick off adding its page // component to the ssr bundle (if that's not already happened) - createServerVisitedPage(pageObj.componentChunkName) + internalStore.dispatch(createServerVisitedPage(pageObj.componentChunkName)) // Ensure the query has been run and written out. try { diff --git a/packages/gatsby/src/utils/source-nodes.ts b/packages/gatsby/src/utils/source-nodes.ts index d07a4dfcdaad3..a087c58f38caf 100644 --- a/packages/gatsby/src/utils/source-nodes.ts +++ b/packages/gatsby/src/utils/source-nodes.ts @@ -81,7 +81,7 @@ function deleteStaleNodes(state: IGatsbyState, nodes: Array): void { const staleNodes = getStaleNodes(state, nodes) if (staleNodes.length > 0) { - staleNodes.forEach(node => deleteNode({ node })) + staleNodes.forEach(node => store.dispatch(deleteNode({ node }))) } } From 7c40198764942ffcb210624173b6b5207475dca7 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 25 Jan 2021 14:36:48 +0100 Subject: [PATCH 08/11] bind action creators in data-tracking test --- packages/gatsby/src/query/__tests__/data-tracking.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/query/__tests__/data-tracking.js b/packages/gatsby/src/query/__tests__/data-tracking.js index b4bfd3098c518..c5d97a5c01e24 100644 --- a/packages/gatsby/src/query/__tests__/data-tracking.js +++ b/packages/gatsby/src/query/__tests__/data-tracking.js @@ -152,12 +152,15 @@ const setup = async ({ restart = isFirstRun, clearCache = false } = {}) => { const { store, emitter } = require(`../../redux`) const { saveState } = require(`../../db`) const reporter = require(`gatsby-cli/lib/reporter`) + const { bindActionCreators } = require(`redux`) const { queryRunner } = require(`../query-runner`) const { actions } = require(`../../redux/actions`) - const doubleBoundActionCreators = Object.keys(actions).reduce( + const boundActionCreators = bindActionCreators(actions, store.dispatch) + + const doubleBoundActionCreators = Object.keys(boundActionCreators).reduce( (acc, actionName) => { acc[actionName] = (...args) => - actions[actionName](...args, { + boundActionCreators[actionName](...args, { name: `gatsby-source-test`, version: `1.0.0`, }) From d0e37db2b1215d6bc8c186db8920f1f532dc8a53 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Tue, 26 Jan 2021 16:31:02 +0100 Subject: [PATCH 09/11] forgot api-runner-node apiCallArgs --- packages/gatsby/src/utils/api-runner-node.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/gatsby/src/utils/api-runner-node.js b/packages/gatsby/src/utils/api-runner-node.js index e83bb8882027e..771b87799f1e8 100644 --- a/packages/gatsby/src/utils/api-runner-node.js +++ b/packages/gatsby/src/utils/api-runner-node.js @@ -415,7 +415,6 @@ const runAPI = async (plugin, api, args, activity) => { ...args, basePath: pathPrefix, pathPrefix: publicPath, - boundActionCreators: actions, actions, loadNodeContent, store, From 79915cd6899f9106600a5f9bd7c69388dbc150d5 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Tue, 9 Feb 2021 14:49:06 +0100 Subject: [PATCH 10/11] fix ts types --- packages/gatsby/src/utils/print-deprecation-warnings.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/utils/print-deprecation-warnings.ts b/packages/gatsby/src/utils/print-deprecation-warnings.ts index 1ae8dcdfcde85..652fa0d9e8774 100644 --- a/packages/gatsby/src/utils/print-deprecation-warnings.ts +++ b/packages/gatsby/src/utils/print-deprecation-warnings.ts @@ -3,8 +3,8 @@ import glob from "glob" import chalk from "chalk" export function printDeprecationWarnings(): void { - const deprecatedApis = [] - const fixMap = {} + const deprecatedApis: ReadonlyArray = [] + const fixMap: Record> = {} const deprecatedLocations: Record> = {} glob From e26ede63f8135a4f99f6b774286fbf4e56ed812c Mon Sep 17 00:00:00 2001 From: LekoArts Date: Wed, 10 Feb 2021 11:08:51 +0100 Subject: [PATCH 11/11] review comments --- packages/gatsby/src/services/create-pages.ts | 3 +-- packages/gatsby/src/utils/dev-ssr/render-dev-html.ts | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/gatsby/src/services/create-pages.ts b/packages/gatsby/src/services/create-pages.ts index 71e7044e522de..9dec865bf8655 100644 --- a/packages/gatsby/src/services/create-pages.ts +++ b/packages/gatsby/src/services/create-pages.ts @@ -3,7 +3,6 @@ import apiRunnerNode from "../utils/api-runner-node" import { IDataLayerContext } from "../state-machines/data-layer/types" import { assertStore } from "../utils/assert-store" import { IGatsbyPage } from "../redux/types" -import { store as internalStore } from "../redux" import { actions } from "../redux/actions" import { deleteUntouchedPages, findChangedPages } from "../utils/changed-pages" @@ -76,7 +75,7 @@ export async function createPages({ ) tim.end() - internalStore.dispatch(actions.apiFinished({ apiName: `createPages` })) + store.dispatch(actions.apiFinished({ apiName: `createPages` })) return { changedPages, diff --git a/packages/gatsby/src/utils/dev-ssr/render-dev-html.ts b/packages/gatsby/src/utils/dev-ssr/render-dev-html.ts index af654a0aa9c71..4cd11f80f2a99 100644 --- a/packages/gatsby/src/utils/dev-ssr/render-dev-html.ts +++ b/packages/gatsby/src/utils/dev-ssr/render-dev-html.ts @@ -7,7 +7,7 @@ import { startListener } from "../../bootstrap/requires-writer" import { findPageByPath } from "../find-page-by-path" import { getPageData as getPageDataExperimental } from "../get-page-data" import { getDevSSRWebpack } from "../../commands/build-html" -import { emitter, store as internalStore } from "../../redux" +import { emitter } from "../../redux" const startWorker = (): any => { const newWorker = new JestWorker(require.resolve(`./render-dev-html-child`), { @@ -135,7 +135,7 @@ export const renderDevHTML = ({ const { createServerVisitedPage } = actions // Record this page was requested. This will kick off adding its page // component to the ssr bundle (if that's not already happened) - internalStore.dispatch(createServerVisitedPage(pageObj.componentChunkName)) + store.dispatch(createServerVisitedPage(pageObj.componentChunkName)) // Ensure the query has been run and written out. try {