Skip to content

Commit 5ba987c

Browse files
committed
fix(source): fix invalid hash ssr/client
1 parent 8df19c3 commit 5ba987c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/runtime/components/SpeedkitImage/classes/Source.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default class Source {
5252
}
5353

5454
get className() {
55-
return `image-${toHashHex(this.src)}`;
55+
return `image-${toHashHex(normalizeSrc(this.src))}`;
5656
}
5757

5858
get style() {
@@ -124,3 +124,11 @@ function getFormat(src, format) {
124124
}
125125
return format || extension;
126126
}
127+
128+
export function normalizeSrc(src) {
129+
if (src.startsWith('/')) {
130+
return src;
131+
}
132+
const url = new URL(src);
133+
return url.pathname + url.search + url.hash;
134+
}

src/runtime/components/SpeedkitPicture/classes/SourceList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Source from '../../SpeedkitImage/classes/Source';
1+
import Source, { normalizeSrc } from '../../SpeedkitImage/classes/Source';
22
import createSort from '#speedkit/externals/create-sort';
33
import { toHashHex } from '#speedkit/utils/string';
44

@@ -52,7 +52,7 @@ export default class SourceList {
5252
}
5353

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

5858
get classNames() {

0 commit comments

Comments
 (0)