Skip to content

Commit 243c562

Browse files
committed
Normale src urls
Normalize both sides of the equality to be sure
1 parent 6f82551 commit 243c562

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/compiler/compile/render_dom/wrappers/Element/Attribute.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
132132
`);
133133
} else if (this.is_src) {
134134
block.chunks.hydrate.push(
135-
b`if (${element.var}.src !== (new URL(${init}, location)).href) ${method}(${element.var}, "${name}", ${this.last});`
135+
b`if (new URL(${element.var}.src, location).href !== (new URL(${init}, location)).href) ${method}(${element.var}, "${name}", ${this.last});`
136136
);
137137
updater = b`${method}(${element.var}, "${name}", ${should_cache ? this.last : value});`;
138138
} else if (property_name) {
@@ -193,7 +193,7 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
193193

194194
if (should_cache) {
195195
condition = this.is_src
196-
? x`${condition} && (${element.var}.src !== (new URL((${last} = ${value}), location)).href)`
196+
? x`${condition} && (new URL(${element.var}.src, location).href !== (new URL((${last} = ${value}), location)).href)`
197197
: x`${condition} && (${last} !== (${last} = ${value}))`;
198198
}
199199

test/js/samples/hydrated-void-element/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function create_fragment(ctx) {
3535
this.h();
3636
},
3737
h() {
38-
if (img.src !== new URL(img_src_value = "donuts.jpg", location).href) attr(img, "src", img_src_value);
38+
if (new URL(img.src, location).href !== new URL(img_src_value = "donuts.jpg", location).href) attr(img, "src", img_src_value);
3939
attr(img, "alt", "donuts");
4040
},
4141
m(target, anchor) {

test/js/samples/src-attribute-check/expected.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ function create_fragment(ctx) {
3535
},
3636
h() {
3737
attr(img0, "alt", "potato");
38-
if (img0.src !== new URL(img0_src_value = /*url*/ ctx[0], location).href) attr(img0, "src", img0_src_value);
38+
if (new URL(img0.src, location).href !== new URL(img0_src_value = /*url*/ ctx[0], location).href) attr(img0, "src", img0_src_value);
3939
attr(img1, "alt", "potato");
40-
if (img1.src !== new URL(img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"), location).href) attr(img1, "src", img1_src_value);
40+
if (new URL(img1.src, location).href !== new URL(img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"), location).href) attr(img1, "src", img1_src_value);
4141
},
4242
m(target, anchor) {
4343
insert(target, img0, anchor);
4444
insert(target, t, anchor);
4545
insert(target, img1, anchor);
4646
},
4747
p(ctx, [dirty]) {
48-
if (dirty & /*url*/ 1 && img0.src !== new URL(img0_src_value = /*url*/ ctx[0], location).href) {
48+
if (dirty & /*url*/ 1 && new URL(img0.src, location).href !== new URL(img0_src_value = /*url*/ ctx[0], location).href) {
4949
attr(img0, "src", img0_src_value);
5050
}
5151

52-
if (dirty & /*slug*/ 2 && img1.src !== new URL(img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"), location).href) {
52+
if (dirty & /*slug*/ 2 && new URL(img1.src, location).href !== new URL(img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"), location).href) {
5353
attr(img1, "src", img1_src_value);
5454
}
5555
},

0 commit comments

Comments
 (0)