-
-
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
fix: ensure beforeNavigate
works on other navigations after clicking a download link
#9747
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: a9c1801 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
beforeNavigate
still runs after clicking a download linkbeforeNavigate
works on other navigations after clicking a download link
Shoot the webkit checks are failing. Probably broke something |
Cancelling |
Regarding the Safari bug: Does this introduce a new bug for Safari users that wasn't there before, or does it "just" not fix it for them? In the latter case I'd be ok with not executing that test until it's fixed in Safari. |
Yes, exactly that. All websites are unable to cancel |
If this means that this PR fixes the problem for all but safari users and there's no way to solve it differently then I'm ok to skip this test for MacOs. I'm a bit surprised though that apparently |
We do have several tests. In hindsight, this changes the way navigation gets cancelled. Currently, it cancels the |
Ok so that means that it does break Safari in ways it didn't before ... shit |
Presumably this would also prevent people from providing their own cancellation UI in the case where an external link is clicked (and there's unsaved work or whatever)? I think we need to keep the existing behaviour but somehow determine more reliably whether a |
|
Ok I think the Small note, the current behaviour for an implicit download link is:
|
*/ | ||
function native_navigation(url) { | ||
location.href = url.href; | ||
return new Promise(() => {}); | ||
return new Promise((resolve) => { | ||
// if we're still on the same page, it was probably a download |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has me a bit uneasy. Are there any situations where this can be true but it is not a download?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only if native_navigation
is being used to navigate to the same page. However, it's currently only used as a fallback when navigating to another page. e.g., clicking a link that has a different href than the current page
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, what if for some reason the response redirected you back to where you came from?
Are we unable to detect that something is a download before starting a navigation that really isn't one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's tricky. Some downloads are only detectable once the response headers have been downloaded and Content-Disposition: attachment
is present. Another option is to revert this and let the developer be explicit about which links are downloads with the download
attribute so they don't run into this issue.
closes #9744
Clicking on a link without the
download
attribute, but returns the response headercontent-disposition: attachment
, will trigger a download instead of an external navigation. Currently, Kit thinks it's an external navigation and that the page will unload.EDIT: The
beforeunload
event is necessary for the implicit download to occur (either that or you have to addtarget="_blank"
.This fix moves thebefore_navigate
call out of theclick
event handler and solely into thebeforeunload
event handler (there was already one there but would check thenavigating
flag to prevent it from stacking with the one from theclick
event handler). Hence, only links that will actually unload the page (external links) will be treated as such, and not get mixed up with these implicit download links (they trigger a download but have nodownload
attribute).EDIT: It seems to be working fine after merging the master branch.
Notes:
Don't know if there's a way to determine if an implicit download link is a download before receiving the response headers. Therefore, SvelteKit will always run
beforeNavigate
and treat it as a 'link' type navigation. Maybe this is fine? The dev can always choose to make the download explicit by adding thedownload
attribute to the link.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.