Skip to content

Commit

Permalink
fix: transform link[rel] shortcut icon and apple-touch-icon to be…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
eltigerchino authored Nov 29, 2024
1 parent 10d0942 commit 67dd214
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/slow-toes-clap.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 67dd214

Please sign in to comment.