Repository: sveltejs/kit (js)

Issue:
Svelte-kit tries to navigate on an a tag with the download attribute
### Describe the bug

When navigating page I want to maintain certain query params and I handle this in my `beforeNavigate`. I have an a tag with the download attribute which shouldn't route, but after clicking it still fires the `beforeNavigate` This download is technically external and it causes the url to not maintain the query params in the url. I also tried adding data-sveltekit-reload to the a tag and still got the same results. It didn't appear to work. This is a confirmed issue on my local machine.

### Reproduction

[Stackblitz Reproduction](https://stackblitz.com/edit/sveltejs-kit-template-default-jsjmtj?file=src%2Froutes%2F%2Blayout.svelte&terminal=dev)

1. Ensure the is a query param of `appKey=12345`
2. Click around the 2 pages and you can see that it maintains the query params in the console from $page
3. after clicking the PDF download button it downloads the pdf and then runs the `beforeNavigate` function (This is when I would expect it not to navigate)
4. Clicking to another page will not maintain query params as the got wiped away from the faulty navigate.

### Logs

_No response_

### System Info

```Shell
System:
    OS: Windows 10 10.0.19044
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
    Memory: 33.15 GB / 63.73 GB
  Binaries:
    Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
    npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (110.0.1587.50)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.91
    @sveltejs/adapter-node: 1.0.0 => 1.0.0
    @sveltejs/kit: 1.5.0 => 1.5.0
    svelte: ^3.54.0 => 3.55.0
```


### Severity

serious, but I can work around it

### Additional Information

This has been tested locally and on stackblitz. The same result occurs. 

Pull request:
run `beforeNavigate` callbacks after cancelled unloading navigation
closes #9170

### Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it solves.
- [x] Ideally, include a test that fails without this PR but passes with it.

### Tests
- [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check`

### Changesets
- [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running `pnpm changeset` and following the prompts. Changesets that add features should be `minor` and those that fix bugs should be `patch`. Please prefix changeset messages with `feat:`, `fix:`, or `chore:`.


Patch:
diff --git a/.changeset/gold-ways-repair.md b/.changeset/gold-ways-repair.md
new file mode 100644
index 000000000..c08ba1148
--- /dev/null
+++ b/.changeset/gold-ways-repair.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+fix: don't prevent `beforeNavigate` callbacks from running following a cancelled unloading navigation
diff --git a/.changeset/itchy-jobs-leave.md b/.changeset/itchy-jobs-leave.md
new file mode 100644
index 000000000..bb6c03672
--- /dev/null
+++ b/.changeset/itchy-jobs-leave.md
@@ -0,0 +1,6 @@
+---
+'@sveltejs/adapter-netlify': patch
+'@sveltejs/adapter-vercel': patch
+---
+
+docs: remove comment discourage direct use of adapters
diff --git a/packages/adapter-netlify/README.md b/packages/adapter-netlify/README.md
index ccbd34426..a5ae3a601 100644
--- a/packages/adapter-netlify/README.md
+++ b/packages/adapter-netlify/README.md
@@ -2,8 +2,6 @@
 
 A SvelteKit adapter that creates a Netlify app.
 
-If you're using [adapter-auto](https://kit.svelte.dev/docs/adapter-auto), you don't need to install this unless you need to specify Netlify-specific options, since it's already included.
-
 ## Docs
 
 [Docs](https://kit.svelte.dev/docs/adapter-netlify)
diff --git a/packages/adapter-vercel/README.md b/packages/adapter-vercel/README.md
index 6c9f1278a..8a09e256d 100644
--- a/packages/adapter-vercel/README.md
+++ b/packages/adapter-vercel/README.md
@@ -2,8 +2,6 @@
 
 A SvelteKit adapter that creates a Vercel app.
 
-If you're using [adapter-auto](https://kit.svelte.dev/docs/adapter-auto), you don't need to install this unless you need to specify Vercel-specific options, since it's already included.
-
 ## Docs
 
 [Docs](https://kit.svelte.dev/docs/adapter-vercel)
diff --git a/packages/kit/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js
index f4c12fe23..41cb3b376 100644
--- a/packages/kit/src/runtime/client/client.js
+++ b/packages/kit/src/runtime/client/client.js
@@ -1521,11 +1521,14 @@ export function create_client(app, target) {
 
 				// Ignore the following but fire beforeNavigate
 				if (external || options.reload) {
-					const navigation = before_navigate({ url, type: 'link' });
-					if (!navigation) {
+					if (before_navigate({ url, type: 'link' })) {
+						// set `navigating` to `true` to prevent `beforeNavigate` callbacks
+						// being called when the page unloads
+						navigating = true;
+					} else {
 						event.preventDefault();
 					}
-					navigating = true;
+
 					return;
 				}
 


Test patch:
diff --git a/packages/kit/test/apps/basics/src/routes/before-navigate/prevent-navigation/+page.svelte b/packages/kit/test/apps/basics/src/routes/before-navigate/prevent-navigation/+page.svelte
index 3f76f2cf9..1e30b09f6 100644
--- a/packages/kit/test/apps/basics/src/routes/before-navigate/prevent-navigation/+page.svelte
+++ b/packages/kit/test/apps/basics/src/routes/before-navigate/prevent-navigation/+page.svelte
@@ -17,6 +17,7 @@
 <h1>prevent navigation</h1>
 <a href="/before-navigate/a">a</a>
 <a href="/before-navigate/redirect">redirect</a>
+<a href="/before-navigate/prevent-navigation?x=1">self</a>
 <a href="https://google.com" target="_blank" rel="noreferrer">_blank</a>
 <a href="https://google.de">external</a>
 <pre>{times_triggered} {unload} {navigation_type}</pre>
diff --git a/packages/kit/test/apps/basics/test/cross-platform/client.test.js b/packages/kit/test/apps/basics/test/cross-platform/client.test.js
index f9109342f..e4d86df02 100644
--- a/packages/kit/test/apps/basics/test/cross-platform/client.test.js
+++ b/packages/kit/test/apps/basics/test/cross-platform/client.test.js
@@ -200,6 +200,19 @@ test.describe('beforeNavigate', () => {
 		await page.goBack();
 		expect(await page.textContent('h1')).toBe('before_navigate_ran: false');
 	});
+
+	test('cancel() on an unloading navigation does not prevent subsequent beforeNavigate callbacks', async ({
+		page,
+		app
+	}) => {
+		await page.goto('/before-navigate/prevent-navigation');
+		await page.click('h1'); // The browsers block attempts to prevent navigation on a frame that's never had a user gesture.
+
+		await app.goto('https://google.de');
+		await app.goto('/before-navigate/prevent-navigation?x=1');
+
+		expect(await page.innerHTML('pre')).toBe('2 false goto');
+	});
 });
 
 test.describe('Scrolling', () => {