Skip to content

Commit

Permalink
fix(gatsby-plugin-sharp): use actions provided, don't assume Gatsby m…
Browse files Browse the repository at this point in the history
…odule location. (gatsbyjs#9986)

The gatsby module resolve by require might not be the gatsby module that is executing. This can occur in mono-repo configurations.

This will prevent the Redux store from receiving the job actions and the bootstrap process will complete without waiting for all images to be processed. This can cause the build to finish without all images being generated.

Fixes gatsbyjs#9984.
  • Loading branch information
martin-css authored and gpetrioli committed Jan 22, 2019
1 parent dd49d9f commit 9832837
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/gatsby-plugin-sharp/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
const { setBoundActionCreators } = require(`./index`)

exports.onPreInit = ({ actions }) => {
setBoundActionCreators(actions)
}

// TODO
// exports.formatJobMessage = jobs => {
// return {
Expand Down
11 changes: 10 additions & 1 deletion packages/gatsby-plugin-sharp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ const getImageSize = file => {
}

const duotone = require(`./duotone`)
const { boundActionCreators } = require(`gatsby/dist/redux/actions`)

// Bound action creators 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 } = require(`gatsby/dist/redux/actions`)
exports.setBoundActionCreators = actions => {
boundActionCreators = actions
}

// Promisify the sharp prototype (methods) to promisify the alternative (for
// raw) callback-accepting toBuffer(...) method
Expand Down

0 comments on commit 9832837

Please sign in to comment.