Skip to content

Commit 54f6a85

Browse files
martin-csspieh
authored andcommitted
fix(gatsby-plugin-sharp): use actions provided, don't assume Gatsby module location. (#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 #9984.
1 parent 8d07c2f commit 54f6a85

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/gatsby-plugin-sharp/src/gatsby-node.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
const { setBoundActionCreators } = require(`./index`)
2+
3+
exports.onPreInit = ({ actions }) => {
4+
setBoundActionCreators(actions)
5+
}
6+
17
// TODO
28
// exports.formatJobMessage = jobs => {
39
// return {

packages/gatsby-plugin-sharp/src/index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ const getImageSize = file => {
3030
}
3131

3232
const duotone = require(`./duotone`)
33-
const { boundActionCreators } = require(`gatsby/dist/redux/actions`)
33+
34+
// Bound action creators should be set when passed to onPreInit in gatsby-node.
35+
// ** It is NOT safe to just directly require the gatsby module **.
36+
// There is no guarantee that the module resolved is the module executing!
37+
// This can occur in mono repos depending on how dependencies have been hoisted.
38+
// The direct require has been left only to avoid breaking changes.
39+
let { boundActionCreators } = require(`gatsby/dist/redux/actions`)
40+
exports.setBoundActionCreators = actions => {
41+
boundActionCreators = actions
42+
}
3443

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

0 commit comments

Comments
 (0)