-
-
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: prevent beforeNavigate()
for download links
#9660
Conversation
🦋 Changeset detectedLatest commit: bd68039 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 |
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.
To me this is not a breaking change but a bug fix - I don't think we ever intended to have this triggered for download, nor do any user want this behavior.
PR looks good to me 👍
Whoops, my mistake. I did wonder if anyone out there actually used it this way. I'm fine with marking it as a patch instead. |
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.
LGTM though i had one small question
|
||
return { url, external, target }; | ||
const download = url?.origin === location.origin && a.hasAttribute('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.
is the origin check necessary or could it just be this?
const download = url?.origin === location.origin && a.hasAttribute('download'); | |
const download = a.hasAttribute('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.
The origin check ensures it only triggers on valid download links.
If a user (for whatever weird reason) has an invalid link such as:
<a href="https://not-the-same-origin.com/file" download>...</a>
The browser navigates to the URL instead of downloading the file. In this case, it could be useful to have beforeNavigate()
run.
fixes #9611
This is a breaking change that causes the client to ignore download links instead of treating them as an external link.
This fixes the issue of the internal
navigating
flag being incorrectly set, leading to missing subsequentbeforeNavigate()
calls.The
navigating
flag prevents thebeforeunload
event from triggering a second round ofbeforeNavigate()
callbacks when an external link is clicked. Because the external link causes the page to unload, Kit doesn't care that thenavigating
flag isn't reset to false. In our download link case, the page isn't unloaded, causing subsequent navigations to not callbeforeNavigate()
. Therefore, we should treat download and external links differently by opting out of the same logic as external links.It's possible for us to still call
beforeNavigate
for download links but downloading isn't really navigating? I'm open to this.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:
.