diff --git a/.changeset/gentle-spies-happen.md b/.changeset/gentle-spies-happen.md new file mode 100644 index 0000000000..faee9e8d42 --- /dev/null +++ b/.changeset/gentle-spies-happen.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: more robust url equality check at dev time diff --git a/packages/svelte/src/internal/client/render.js b/packages/svelte/src/internal/client/render.js index d6ce2adc42..0658780b2f 100644 --- a/packages/svelte/src/internal/client/render.js +++ b/packages/svelte/src/internal/client/render.js @@ -2295,9 +2295,6 @@ export function attr(dom, attribute, value) { } } -/** @type {HTMLAnchorElement | undefined} */ -let src_url_equal_anchor; - /** * @param {string} element_src * @param {string} url @@ -2305,12 +2302,7 @@ let src_url_equal_anchor; */ function src_url_equal(element_src, url) { if (element_src === url) return true; - if (!src_url_equal_anchor) { - src_url_equal_anchor = document.createElement('a'); - } - // This is actually faster than doing URL(..).href - src_url_equal_anchor.href = url; - return element_src === src_url_equal_anchor.href; + return new URL(element_src, document.baseURI).href === new URL(url, document.baseURI).href; } /** @param {string} srcset */