kit icon indicating copy to clipboard operation
kit copied to clipboard

beforeNavigate shouldn't trigger when <a target="_blank">

Open oodavid opened this issue 3 years ago • 1 comments

Describe the bugs

I've grouped together two behavioural issues as they feel related:

  1. Links that open in a new tab / window should not trigger beforeNavigate.

  2. It would be useful to be notified whether navigation.cancel() will trigger the browser beforeunload behaviour. Or, if we could choose whether to trigger that behaviour. As it stands it's not possible to know whether to handle the beforeUnload event with our own UI. In my first (naive) use of navigation.cancel(), I created my own confirmation UI in Svelte. The final result was that some navigation events would have just my UI, and others would have the native UI and my UI.

Reproduction

https://github.com/oodavid/sveltekit-beforeUnload - instructions

https://www.loom.com/share/3fbc000bbbaa4e65b1e64f304d0fddee - video explanation

Logs

No response

System Info

System:
    OS: macOS 12.3.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 32.05 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.18.1 - ~/.nvm/versions/node/v16.18.1/bin/node
    npm: 8.19.2 - ~/.nvm/versions/node/v16.18.1/bin/npm
  Browsers:
    Chrome: 108.0.5359.124
    Edge: 108.0.1462.76
    Firefox: 105.0.1
    Safari: 15.4
  npmPackages:
    @sveltejs/adapter-auto: ^1.0.0 => 1.0.0 
    @sveltejs/kit: ^1.0.0 => 1.0.11 
    svelte: ^3.54.0 => 3.55.1 
    vite: ^4.0.0 => 4.0.4

Severity

annoyance

Additional Information

No response

oodavid avatar Jan 12 '23 13:01 oodavid

Thanks for the thorough reproduction and the video!

beforeNavigate firing for links opening in a new tab is definitely a bug.

Navigation links not triggering an alert dialog could be found out by looking at the type property which is different for these scenarios (link/goto/form would not trigger the native dialog, and popstate only if the link in question is external). We should probably document this.

dummdidumm avatar Jan 16 '23 21:01 dummdidumm

Hi, I actually really want this to work for target=_blank links. Is this still possible somehow?

AbstractFruitFactory avatar Nov 02 '23 08:11 AbstractFruitFactory