beforeNavigate shouldn't trigger when <a target="_blank">
Describe the bugs
I've grouped together two behavioural issues as they feel related:
-
Links that open in a new tab / window should not trigger beforeNavigate.
-
It would be useful to be notified whether
navigation.cancel()will trigger the browserbeforeunloadbehaviour. 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 ofnavigation.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
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.
Hi, I actually really want this to work for target=_blank links. Is this still possible somehow?