From 243c56229866a64fd80c95c5249737e7a6e39a34 Mon Sep 17 00:00:00 2001 From: Altan Birler Date: Fri, 25 Jun 2021 18:29:55 +0200 Subject: [PATCH] Normale src urls Normalize both sides of the equality to be sure --- .../compile/render_dom/wrappers/Element/Attribute.ts | 4 ++-- test/js/samples/hydrated-void-element/expected.js | 2 +- test/js/samples/src-attribute-check/expected.js | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts index 0f7c2b4c59cd..c8a84a4e0b39 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts @@ -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) { @@ -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}))`; } diff --git a/test/js/samples/hydrated-void-element/expected.js b/test/js/samples/hydrated-void-element/expected.js index d30bc46cb068..cd837769cb24 100644 --- a/test/js/samples/hydrated-void-element/expected.js +++ b/test/js/samples/hydrated-void-element/expected.js @@ -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) { diff --git a/test/js/samples/src-attribute-check/expected.js b/test/js/samples/src-attribute-check/expected.js index 8a8a2d6fca86..f8174e948a26 100644 --- a/test/js/samples/src-attribute-check/expected.js +++ b/test/js/samples/src-attribute-check/expected.js @@ -35,9 +35,9 @@ 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); @@ -45,11 +45,11 @@ function create_fragment(ctx) { 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); } },