Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby-plugin-image): Normalize filename for correct hashing #37262

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export default function attrs({
}

// Adding the filename to the hashing, like in "extractStaticImageProps" function
props.filename = state.filename
if (state.filename) {
props.filename = slash(state.filename)
}
const hash = hashOptions(props)

const cacheDir = (this.opts as Record<string, string>)?.cacheDir
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-plugin-image/src/node-apis/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NodePath } from "@babel/core"
import { JSXOpeningElement } from "@babel/types"
import { parse, ParserOptions } from "@babel/parser"
import babel from "@babel/core"
import { slash } from "gatsby-core-utils"
import { evaluateImageAttributes, hashOptions } from "../babel-helpers"
import { IStaticImageProps } from "../components/static-image.server"

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

images.set(hashOptions(image), image)
},
Expand Down