Skip to content

Commit

Permalink
Normale src urls
Browse files Browse the repository at this point in the history
Normalize both sides of the equality to be sure
  • Loading branch information
hbirler committed Jun 25, 2021
1 parent 6f82551 commit 243c562
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/compiler/compile/render_dom/wrappers/Element/Attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
`);
} else if (this.is_src) {
block.chunks.hydrate.push(
b`if (${element.var}.src !== (new URL(${init}, location)).href) ${method}(${element.var}, "${name}", ${this.last});`
b`if (new URL(${element.var}.src, location).href !== (new URL(${init}, location)).href) ${method}(${element.var}, "${name}", ${this.last});`
);
updater = b`${method}(${element.var}, "${name}", ${should_cache ? this.last : value});`;
} else if (property_name) {
Expand Down Expand Up @@ -193,7 +193,7 @@ export default class AttributeWrapper extends BaseAttributeWrapper {

if (should_cache) {
condition = this.is_src
? x`${condition} && (${element.var}.src !== (new URL((${last} = ${value}), location)).href)`
? x`${condition} && (new URL(${element.var}.src, location).href !== (new URL((${last} = ${value}), location)).href)`
: x`${condition} && (${last} !== (${last} = ${value}))`;
}

Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/hydrated-void-element/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function create_fragment(ctx) {
this.h();
},
h() {
if (img.src !== new URL(img_src_value = "donuts.jpg", location).href) attr(img, "src", img_src_value);
if (new URL(img.src, location).href !== new URL(img_src_value = "donuts.jpg", location).href) attr(img, "src", img_src_value);
attr(img, "alt", "donuts");
},
m(target, anchor) {
Expand Down
8 changes: 4 additions & 4 deletions test/js/samples/src-attribute-check/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ function create_fragment(ctx) {
},
h() {
attr(img0, "alt", "potato");
if (img0.src !== new URL(img0_src_value = /*url*/ ctx[0], location).href) attr(img0, "src", img0_src_value);
if (new URL(img0.src, location).href !== new URL(img0_src_value = /*url*/ ctx[0], location).href) attr(img0, "src", img0_src_value);
attr(img1, "alt", "potato");
if (img1.src !== new URL(img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"), location).href) attr(img1, "src", img1_src_value);
if (new URL(img1.src, location).href !== new URL(img1_src_value = "" + (/*slug*/ ctx[1] + ".jpg"), location).href) attr(img1, "src", img1_src_value);
},
m(target, anchor) {
insert(target, img0, anchor);
insert(target, t, anchor);
insert(target, img1, anchor);
},
p(ctx, [dirty]) {
if (dirty & /*url*/ 1 && img0.src !== new URL(img0_src_value = /*url*/ ctx[0], location).href) {
if (dirty & /*url*/ 1 && new URL(img0.src, location).href !== new URL(img0_src_value = /*url*/ ctx[0], location).href) {
attr(img0, "src", img0_src_value);
}

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

0 comments on commit 243c562

Please sign in to comment.