Skip to content

Commit 001e045

Browse files
authored
fix(gatsby-transformer-sharp): create child nodes only for Files (#27992)
1 parent 3fda83b commit 001e045

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

packages/gatsby-transformer-sharp/src/__tests__/__snapshots__/gatsby-node.js.snap

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,10 @@ Array [
3535
"id": "whatever",
3636
"internal": Object {
3737
"contentDigest": "whatever",
38+
"type": "File",
3839
},
3940
},
4041
},
4142
],
4243
]
4344
`;
44-
45-
exports[`Process image nodes correctly doesn't create an ImageSharp node for a .gif file 1`] = `Array []`;
46-
47-
exports[`Process image nodes correctly doesn't create an ImageSharp node for a .gif file 2`] = `Array []`;

packages/gatsby-transformer-sharp/src/__tests__/gatsby-node.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe(`Process image nodes correctly`, () => {
88
children: [],
99
internal: {
1010
contentDigest: `whatever`,
11+
type: `File`,
1112
},
1213
}
1314
const createNode = jest.fn()
@@ -34,6 +35,33 @@ describe(`Process image nodes correctly`, () => {
3435
children: [],
3536
internal: {
3637
contentDigest: `whatever`,
38+
type: `File`,
39+
},
40+
}
41+
const createNode = jest.fn()
42+
const createParentChildLink = jest.fn()
43+
const actions = { createNode, createParentChildLink }
44+
const createNodeId = jest.fn()
45+
createNodeId.mockReturnValue(`uuid-from-gatsby`)
46+
47+
await onCreateNode({
48+
node,
49+
actions,
50+
createNodeId,
51+
}).then(() => {
52+
expect(createNode).toHaveBeenCalledTimes(0)
53+
expect(createParentChildLink).toHaveBeenCalledTimes(0)
54+
})
55+
})
56+
57+
it(`doesn't create an ImageSharp node if parent is not a File`, async () => {
58+
const node = {
59+
extension: `png`,
60+
id: `whatever`,
61+
children: [],
62+
internal: {
63+
contentDigest: `whatever`,
64+
type: `NotAFile`,
3765
},
3866
}
3967
const createNode = jest.fn()
@@ -47,8 +75,6 @@ describe(`Process image nodes correctly`, () => {
4775
actions,
4876
createNodeId,
4977
}).then(() => {
50-
expect(createNode.mock.calls).toMatchSnapshot()
51-
expect(createParentChildLink.mock.calls).toMatchSnapshot()
5278
expect(createNode).toHaveBeenCalledTimes(0)
5379
expect(createParentChildLink).toHaveBeenCalledTimes(0)
5480
})

packages/gatsby-transformer-sharp/src/on-node-create.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { supportedExtensions } = require(`./supported-extensions`)
22

33
function unstable_shouldOnCreateNode({ node }) {
4-
return !!supportedExtensions[node.extension]
4+
return node.internal.type === `File` && !!supportedExtensions[node.extension]
55
}
66

77
module.exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode

0 commit comments

Comments
 (0)