Skip to content

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

@oodavid

Description

@oodavid

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/tree/2af0ef6271242397da1491f74608750f7c28e886 - repo (note that this is pointing at a specific commit!)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions