-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
beforeNavigate doesn't trigger default browser behaviour as-per the docs #8597
Comments
Probably because of the |
Is there anything I can do to help figure that out? I've not defined |
When we click a link and call
We can't fix this without allowing the I think we should keep the behaviour consistent. So either: |
I slightly lean twoards never showing the native dialog by default, you likely want to provide your own slick UI instead, but in the case of closing the tab (not clicking a link) it's just not possible to do anything else other than showing the native confirmation dialog (for security etc reasons). That leaves us only with the other option of always showing the native UI on external link clicks, which has the drawback of #9747 (comment) . I'm not sure how big of a deal this is in practise. A way out of the inconsistency would be #8625, in other words Gah, this is impossible to get right in all cases... My response at this point is "browsers are complicated, it isn't completely consistent, sorry". |
Thinking about it again, it would be easy enough for a user to check if the navigation type is a link and if the page will unload. beforeNavigate(({ type, cancel, willUnload }) => {
if (type === link && willUnload) {
// show custom ui
} else {
// show native browser dialog
cancel()
}
}); What do you think? They can only show the custom dialog on link clicks anyway. Maybe cancel needs a more fitting name for its behaviour too? |
I don't think that's quite right — If I understand #8625 correctly, the proposal is that clicking on an external link wouldn't invoke There's something very appealing about that solution — it would allow us to get rid of It also means that you'd need to have the cancellation logic in two places: let unsaved_changes = false;
beforeNavigate(({ cancel }) => {
if (unsaved_changes) cancel();
show_custom_ui();
});
beforeUnload(({ cancel }) => {
if (unsaved_changes) cancel();
}); (Side-note: there's really no point in having a
It's simpler than that — we just need to check whether beforeNavigate(({ type, cancel }) => {
cancel();
if (type !== 'leave') {
show_custom_ui();
}
}); It is arguably a little bit confusing that So I think there are two possibilities:
|
Ok, here's the PR where So I think this is just a documentation issue. I'll open a PR. |
Describe the bug
A follow-up from #8482.
The beforeNavigate documentation states that:
When linking to an external site, we're told that
{ ... navigation.willUnload: true }
, but the native browser unload confirmation dialog doesn't appear as expected.Reproduction
https://github.com/oodavid/sveltekit-beforeUnload - reproduction
https://www.loom.com/share/4e3b04fc7def408c9010285e960e0577 - walkthrough video (1m 45s)
Logs
No response
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: