Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: decode hash when clicking on same hash to correctly scroll on non ascii hashes #12699

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smooth-dogs-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: decode non ASCII anchor hashes when scrolling into view
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
<div style="height: 180vh; background-color: honeydew;">
<p id="go-to-.=" class="special-char-id">The browser scrolls to me</p>
</div>
<a id="non-ascii-anchor" href="#go-to-encöded">Anchor demo (non-ASCII)</a>
14 changes: 14 additions & 0 deletions packages/kit/test/apps/basics/test/cross-platform/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
test.describe.configure({ mode: 'parallel' });

test.describe('a11y', () => {
test('resets focus', async ({ page, clicknav, browserName }) => {

Check warning on line 12 in packages/kit/test/apps/basics/test/cross-platform/client.test.js

View workflow job for this annotation

GitHub Actions / test-kit-cross-browser (18, windows-2019, chromium, dev)

flaky test: resets focus

retries: 2
const tab = browserName === 'webkit' ? 'Alt+Tab' : 'Tab';

await page.goto('/accessibility/a');
Expand All @@ -33,7 +33,7 @@
expect(await page.evaluate(() => document.documentElement.getAttribute('tabindex'))).toBe(null);
});

test('applies autofocus after a navigation', async ({ page, clicknav }) => {

Check warning on line 36 in packages/kit/test/apps/basics/test/cross-platform/client.test.js

View workflow job for this annotation

GitHub Actions / test-kit-cross-browser (18, windows-2019, chromium, dev)

flaky test: applies autofocus after a navigation

retries: 2
await page.goto('/accessibility/autofocus/a');

await clicknav('[href="/accessibility/autofocus/b"]');
Expand Down Expand Up @@ -280,6 +280,20 @@
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,
Expand Down Expand Up @@ -782,7 +796,7 @@
test('trailing slash redirect', async ({ page, clicknav }) => {
await page.goto('/routing/trailing-slash');

await clicknav('a[href="/routing/trailing-slash/always"]');

Check warning on line 799 in packages/kit/test/apps/basics/test/cross-platform/client.test.js

View workflow job for this annotation

GitHub Actions / test-kit-cross-browser (18, ubuntu-latest, firefox, build)

flaky test: responds to <form target="_blank"> submission with new tab

retries: 2
expect(new URL(page.url()).pathname).toBe('/routing/trailing-slash/always/');
await expect(page.locator('p')).toHaveText('/routing/trailing-slash/always/');

Expand All @@ -796,7 +810,7 @@
});

test('trailing slash redirect works when navigating from root page', async ({
page,

Check warning on line 813 in packages/kit/test/apps/basics/test/cross-platform/client.test.js

View workflow job for this annotation

GitHub Actions / test-kit-cross-browser (18, ubuntu-latest, firefox, build)

flaky test: responds to <button formtarget="_blank" submission with new tab

retries: 2
clicknav
}) => {
await page.goto('/');
Expand Down
Loading