diff --git a/.changeset/smooth-dogs-travel.md b/.changeset/smooth-dogs-travel.md new file mode 100644 index 000000000000..0a33331f1f5f --- /dev/null +++ b/.changeset/smooth-dogs-travel.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: decode non ASCII anchor hashes when scrolling into view diff --git a/packages/kit/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js index 2f4099c6cb50..5f251a07362f 100644 --- a/packages/kit/src/runtime/client/client.js +++ b/packages/kit/src/runtime/client/client.js @@ -2121,7 +2121,7 @@ function _start_router() { if (hash === '' || (hash === 'top' && a.ownerDocument.getElementById('top') === null)) { window.scrollTo({ top: 0 }); } else { - a.ownerDocument.getElementById(hash)?.scrollIntoView(); + a.ownerDocument.getElementById(decodeURIComponent(hash))?.scrollIntoView(); } return; diff --git a/packages/kit/test/apps/basics/src/routes/anchor/anchor/+page.svelte b/packages/kit/test/apps/basics/src/routes/anchor/anchor/+page.svelte index 2cf545d88a6b..c977dfcf429c 100644 --- a/packages/kit/test/apps/basics/src/routes/anchor/anchor/+page.svelte +++ b/packages/kit/test/apps/basics/src/routes/anchor/anchor/+page.svelte @@ -8,3 +8,4 @@

The browser scrolls to me

+Anchor demo (non-ASCII) diff --git a/packages/kit/test/apps/basics/test/cross-platform/client.test.js b/packages/kit/test/apps/basics/test/cross-platform/client.test.js index 7f57086b4048..5e1a8b258f00 100644 --- a/packages/kit/test/apps/basics/test/cross-platform/client.test.js +++ b/packages/kit/test/apps/basics/test/cross-platform/client.test.js @@ -280,6 +280,20 @@ test.describe('Scrolling', () => { expect(await in_view('#go-to-encöded')).toBe(true); }); + test('url-supplied non-ascii anchor works on navigation to page after manual scroll', async ({ + page, + in_view, + clicknav + }) => { + await page.goto('/anchor'); + await clicknav('#non-ascii-anchor'); + await page.evaluate(() => { + window.scrollTo(0, 50); + }); + await page.locator('#non-ascii-anchor').click(); + expect(await in_view('#go-to-encöded')).toBe(true); + }); + test('url-supplied anchor with special characters works on navigation to page', async ({ page, in_view,