From 67dd214863cbc5852eb0e8512efbb7bad5358e8a Mon Sep 17 00:00:00 2001 From: Tee Ming Date: Sat, 30 Nov 2024 01:34:40 +0800 Subject: [PATCH] fix: transform link[rel] `shortcut icon` and `apple-touch-icon` to be absolute (#13077) closes #10317 This PR builds upon https://github.com/sveltejs/kit/pull/5583/files to include the shortcut icon and apple-touch-icon rel attributes in addition just icon when transforming the asset URL to be absolute. --- .changeset/slow-toes-clap.md | 5 +++++ packages/kit/src/runtime/client/client.js | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/slow-toes-clap.md diff --git a/.changeset/slow-toes-clap.md b/.changeset/slow-toes-clap.md new file mode 100644 index 000000000000..77838348c450 --- /dev/null +++ b/.changeset/slow-toes-clap.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: transform link[rel='shortcut icon'] and link[rel='apple-touch-icon'] to be absolute to avoid console error when navigating diff --git a/packages/kit/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js index 37660a425e65..09618a4b2b9e 100644 --- a/packages/kit/src/runtime/client/client.js +++ b/packages/kit/src/runtime/client/client.js @@ -46,6 +46,8 @@ import { INVALIDATED_PARAM, TRAILING_SLASH_PARAM, validate_depends } from '../sh import { get_message, get_status } from '../../utils/error.js'; import { writable } from 'svelte/store'; +const ICON_REL_ATTRIBUTES = new Set(['icon', 'shortcut icon', 'apple-touch-icon']); + let errored = false; // We track the scroll position associated with each history entry in sessionStorage, @@ -2307,7 +2309,9 @@ function _start_router() { // URLs after a pushState/replaceState, resulting in a 404 — see // https://github.com/sveltejs/kit/issues/3748#issuecomment-1125980897 for (const link of document.querySelectorAll('link')) { - if (link.rel === 'icon') link.href = link.href; // eslint-disable-line + if (ICON_REL_ATTRIBUTES.has(link.rel)) { + link.href = link.href; // eslint-disable-line + } } addEventListener('pageshow', (event) => {