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

Middle-clicking hash links may not jump #10245

Closed
nilslindemann opened this issue Jun 24, 2023 · 4 comments · Fixed by sveltejs/svelte#8880
Closed

Middle-clicking hash links may not jump #10245

nilslindemann opened this issue Jun 24, 2023 · 4 comments · Fixed by sveltejs/svelte#8880

Comments

@nilslindemann
Copy link

nilslindemann commented Jun 24, 2023

Describe the bug

Middle-clicking hash links on https://kit.svelte.dev/ may sometimes not jump to the hash.

Reproduction

Go to kit.svelte.dev/docs/errors. Middle-click on the first two hash links, "Error" and "type safety".

The "Error" link will, but the "type safety" link will not jump to the hash in the new tab, in these browsers:

  • Chrome 114.0.5735.133
  • Chromium 114.0.5735.133

(tested with fresh installs)

It will jump in these browsers:

  • Firefox 114.0.2 (fresh install)
  • Ungoogled Chromium 114.0.5735.106 (though I am not 100% sure if it did all the time, see below).

Interesting: developer.mozilla.org/.../Object/defineProperty also shows the same behavior in Chrome and Chromium 114.0.5735.133, and also in Ungoogled Chromium 114.0.5735.106 (weird), but it works in Firefox 114.0.2.

So, this may be a bug recently (re?)introduced in Chrome?

#4216 may be related. I can confirm that the link posted there does only scroll to the hash in Firefox. Middle clicking it in Chrome, Chromium and Ungoogled Chromium does not scroll to the hash.

For the records, the following document works in all browsers, middle-clicking the hash link jumps to the hash in the new tab:

<!DOCTYPE html><html lang="EN"><title>Jump to hash test</title><style>p { margin-bottom:1000px; }</style>

<p><a href="#hash">Jump to #hash</a></p>
<p id="hash">#hash</p>

</html>

Logs

No response

System Info

System:
    OS: Linux 5.15 Linux Mint 21.1 (Vera)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    Memory: 12.10 GB / 15.36 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.3.1 - ~/Node.js/v20.3.1/bin/node
    Yarn: 1.22.19 - ~/Node.js/v20.3.1/bin/yarn
    npm: 9.7.2 - ~/Node.js/v20.3.1/bin/npm

Severity

annoyance

Additional Information

My guess is, SvelteKit tries to jump to something which is not yet rendered?

@nilslindemann
Copy link
Author

Also does not work in this version of Chrome and Chromium:

114.0.5735.198

dummdidumm added a commit to sveltejs/svelte that referenced this issue Jun 29, 2023
@dummdidumm
Copy link
Member

This goes back to a bug within Svelte itself, where certain @html tags are not hydrated correctly, which means they get removed and reappended to the dom. Chrome doesn't find the id (race condition probably) and therefore doesn't scroll.

@nilslindemann
Copy link
Author

BTW, I just tested this locally and there, both links scroll to the correct position in all browsers. It just does not work over the internet.

dummdidumm added a commit to sveltejs/svelte that referenced this issue Jul 3, 2023
html tags that could be optimized to use innerHTML in mount ignored any hydration code, which leads to everything getting unmounted and mounted again. This takes the non-optimized path for hydration, too.

fixes sveltejs/kit#10245
@nilslindemann
Copy link
Author

nilslindemann commented Jul 3, 2023

@dummdidumm Why are you closing it? I still see the bug on the current website. The issue persists.

Edit: It is fixed. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants