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

Error: navigation was cancelled thrown in console when using navigation.cancel() in beforeNavigate #10665

Closed
MathiasWP opened this issue Sep 1, 2023 · 0 comments · Fixed by #10666

Comments

@MathiasWP
Copy link
Contributor

MathiasWP commented Sep 1, 2023

Describe the bug

Sveltekit throws an error when using navigation.cancel() in beforeNavigate:

<script>
    import { beforeNavigate } from '$app/navigation';

    beforeNavigate((navigation) => {
   		// this throws an error
        navigation.cancel();
    })
</script>

<a href="/other">Cancel navigation</a>

Not sure if this is expected behaviour, but the error is caught by our Sentry logging, which is kind of annoying when it's not really an error.

Reproduction

https://github.com/MathiasWP/sveltekit-navigation-cancel-repro

Logs

client.js?v=2cc7adfe:927 Uncaught (in promise) Error: navigation was cancelled
    at Object.cancel (client.js?v=2cc7adfe:927:16)
    at +page.svelte:5:20
    at client.js?v=2cc7adfe:933:46
    at Array.forEach (<anonymous>)
    at before_navigate (client.js?v=2cc7adfe:933:30)
    at navigate (client.js?v=2cc7adfe:969:15)
    at HTMLHtmlElement.<anonymous> (client.js?v=2cc7adfe:1594:5)


### System Info

```Shell
System:
    OS: macOS 13.5.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 53.38 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.9.0 - /usr/local/bin/node
    npm: 9.1.1 - /usr/local/bin/npm
  Browsers:
    Brave Browser: 116.1.57.53
    Chrome: 116.0.5845.140
    Firefox: 112.0.2
    Safari: 16.6
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0 
    @sveltejs/kit: ^1.20.4 => 1.24.0 
    svelte: ^4.0.5 => 4.2.0 
    vite: ^4.4.2 => 4.4.9

Severity

annoyance

Additional Information

Most likely caused by this PR: #9605

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.

1 participant