Skip to content

Commit b7477f4

Browse files
gatsbybotLekoArts
andauthoredDec 14, 2022
fix(gatsby-plugin-image): Normalize filename for correct hashing (#37262) (#37263)
* initial * add peace of mind (cherry picked from commit 397fa3f) Co-authored-by: Lennart <lekoarts@gmail.com>
1 parent 98cbee1 commit b7477f4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
 

‎packages/gatsby-plugin-image/src/babel-plugin-parse-static-images.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ export default function attrs({
5050
}
5151

5252
// Adding the filename to the hashing, like in "extractStaticImageProps" function
53-
props.filename = state.filename
53+
if (state.filename) {
54+
props.filename = slash(state.filename)
55+
}
5456
const hash = hashOptions(props)
5557

5658
const cacheDir = (this.opts as Record<string, string>)?.cacheDir

‎packages/gatsby-plugin-image/src/node-apis/parser.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NodePath } from "@babel/core"
33
import { JSXOpeningElement } from "@babel/types"
44
import { parse, ParserOptions } from "@babel/parser"
55
import babel from "@babel/core"
6+
import { slash } from "gatsby-core-utils"
67
import { evaluateImageAttributes, hashOptions } from "../babel-helpers"
78
import { IStaticImageProps } from "../components/static-image.server"
89

@@ -96,7 +97,8 @@ export const extractStaticImageProps = (
9697
) as unknown as IStaticImageProps
9798
// When the image props are the same for multiple StaticImage but they are in different locations
9899
// the hash will be the same then. We need to make sure that the hash is unique.
99-
image.filename = filename
100+
// The filename should already be normalized but better safe than sorry.
101+
image.filename = slash(filename)
100102

101103
images.set(hashOptions(image), image)
102104
},

0 commit comments

Comments
 (0)
Please sign in to comment.