Skip to content

Commit

Permalink
fix(source): fix invalid hash ssr/client
Browse files Browse the repository at this point in the history
  • Loading branch information
ThornWalli committed Feb 8, 2024
1 parent 8df19c3 commit 5ba987c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/runtime/components/SpeedkitImage/classes/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class Source {
}

get className() {
return `image-${toHashHex(this.src)}`;
return `image-${toHashHex(normalizeSrc(this.src))}`;
}

get style() {
Expand Down Expand Up @@ -124,3 +124,11 @@ function getFormat(src, format) {
}
return format || extension;
}

export function normalizeSrc(src) {
if (src.startsWith('/')) {
return src;
}
const url = new URL(src);
return url.pathname + url.search + url.hash;
}
4 changes: 2 additions & 2 deletions src/runtime/components/SpeedkitPicture/classes/SourceList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Source from '../../SpeedkitImage/classes/Source';
import Source, { normalizeSrc } from '../../SpeedkitImage/classes/Source';
import createSort from '#speedkit/externals/create-sort';
import { toHashHex } from '#speedkit/utils/string';

Expand Down Expand Up @@ -52,7 +52,7 @@ export default class SourceList {
}

get className() {
return `picture-${toHashHex(this.sorted.map(({ src }) => src).join(','))}`;
return `picture-${toHashHex(this.sorted.map(({ src }) => normalizeSrc(src)).join(','))}`;
}

get classNames() {
Expand Down

0 comments on commit 5ba987c

Please sign in to comment.