Repository: sveltejs/kit (js)

Issue:
search index includes hidden code
### Describe the bug

If you search for a word like `ambient`, the search results will show code that is used for shiki-twoslash but isn't rendered

<img width="510" alt="image" src="https://user-images.githubusercontent.com/1162160/212999259-b5a5cd81-be81-49ce-b7ba-df520ba629ee.png">


Pull request:
site: remove hidden code
closes #8572

Patch:
diff --git a/packages/kit/CHANGELOG.md b/packages/kit/CHANGELOG.md
index 0c9e5f70f..482738a9b 100644
--- a/packages/kit/CHANGELOG.md
+++ b/packages/kit/CHANGELOG.md
@@ -1,5 +1,13 @@
 # @sveltejs/kit
 
+## 1.1.3
+
+### Patch Changes
+
+- docs: explain how to add ambient typings ([#8558](https://github.com/sveltejs/kit/pull/8558))
+
+- fix: ignore `target="_blank"` links ([#8563](https://github.com/sveltejs/kit/pull/8563))
+
 ## 1.1.2
 
 ### Patch Changes
diff --git a/packages/kit/package.json b/packages/kit/package.json
index 38dc5a728..a3ca83698 100644
--- a/packages/kit/package.json
+++ b/packages/kit/package.json
@@ -1,6 +1,6 @@
 {
 	"name": "@sveltejs/kit",
-	"version": "1.1.2",
+	"version": "1.1.3",
 	"repository": {
 		"type": "git",
 		"url": "https://github.com/sveltejs/kit",
diff --git a/packages/kit/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js
index 4367a1e35..a6335a948 100644
--- a/packages/kit/src/runtime/client/client.js
+++ b/packages/kit/src/runtime/client/client.js
@@ -1389,10 +1389,17 @@ export function create_client({ target, base }) {
 				const a = find_anchor(/** @type {Element} */ (event.composedPath()[0]), container);
 				if (!a) return;
 
-				const { url, external, has } = get_link_info(a, base);
-				const options = get_router_options(a);
+				const { url, external, target } = get_link_info(a, base);
 				if (!url) return;
 
+				// bail out before `beforeNavigate` if link opens in a different tab
+				if (target === '_parent' || target === '_top') {
+					if (window.parent !== window) return;
+				} else if (target && target !== '_self') {
+					return;
+				}
+
+				const options = get_router_options(a);
 				const is_svg_a_element = a instanceof SVGAElement;
 
 				// Ignore URL protocols that differ to the current one and are not http(s) (e.g. `mailto:`, `tel:`, `myapp:`, etc.)
@@ -1410,8 +1417,6 @@ export function create_client({ target, base }) {
 				)
 					return;
 
-				if (has.download) return;
-
 				// Ignore the following but fire beforeNavigate
 				if (external || options.reload) {
 					const navigation = before_navigate({ url, type: 'link' });
diff --git a/packages/kit/src/runtime/client/utils.js b/packages/kit/src/runtime/client/utils.js
index c0f56a34e..8c924c35b 100644
--- a/packages/kit/src/runtime/client/utils.js
+++ b/packages/kit/src/runtime/client/utils.js
@@ -124,16 +124,16 @@ export function get_link_info(a, base) {
 		url = new URL(a instanceof SVGAElement ? a.href.baseVal : a.href, document.baseURI);
 	} catch {}
 
-	const has = {
-		rel_external: (a.getAttribute('rel') || '').split(/\s+/).includes('external'),
-		download: a.hasAttribute('download'),
-		target: !!(a instanceof SVGAElement ? a.target.baseVal : a.target)
-	};
+	const target = a instanceof SVGAElement ? a.target.baseVal : a.target;
 
 	const external =
-		!url || is_external_url(url, base) || has.rel_external || has.target || has.download;
+		!url ||
+		!!target ||
+		is_external_url(url, base) ||
+		(a.getAttribute('rel') || '').split(/\s+/).includes('external') ||
+		a.hasAttribute('download');
 
-	return { url, has, external };
+	return { url, external, target };
 }
 
 /**
diff --git a/packages/kit/types/ambient.d.ts b/packages/kit/types/ambient.d.ts
index f781c274d..57d62ce63 100644
--- a/packages/kit/types/ambient.d.ts
+++ b/packages/kit/types/ambient.d.ts
@@ -11,9 +11,12 @@
  * 	}
  * }
  *
- * export default undefined;
+ * export {};
  * ```
  *
+ * The `export {}` line exists because without it, the file would be treated as an _ambient module_ which prevents you from adding `import` declarations.
+ * If you need to add ambient `declare module` declarations, do so in a separate file like `src/ambient.d.ts`.
+ *
  * By populating these interfaces, you will gain type safety when using `event.locals`, `event.platform`, and `data` from `load` functions.
  */
 declare namespace App {
@@ -243,7 +246,8 @@ declare module '$app/navigation' {
 
 	/**
 	 * A navigation interceptor that triggers before we navigate to a new URL, whether by clicking a link, calling `goto(...)`, or using the browser back/forward controls.
-	 * Calling `cancel()` will prevent the navigation from completing.
+	 * Calling `cancel()` will prevent the navigation from completing. If the navigation would have directly unloaded the current page, calling `cancel` will trigger the native
+	 * browser unload confirmation dialog. In these cases, `navigation.willUnload` is `true`.
 	 *
 	 * When a navigation isn't client side, `navigation.to.route.id` will be `null`.
 	 *
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index bc95ada61..36bdea80f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -685,7 +685,7 @@ importers:
       '@sveltejs/adapter-vercel': workspace:^1.0.4
       '@sveltejs/amp': workspace:^
       '@sveltejs/kit': workspace:^
-      '@sveltejs/site-kit': ^3.0.3
+      '@sveltejs/site-kit': ^3.1.0
       '@types/d3-geo': ^3.0.2
       '@types/node': ^16.18.6
       d3-geo: ^3.0.1
@@ -711,7 +711,7 @@ importers:
       '@sveltejs/adapter-vercel': link:../../packages/adapter-vercel
       '@sveltejs/amp': link:../../packages/amp
       '@sveltejs/kit': link:../../packages/kit
-      '@sveltejs/site-kit': 3.0.3
+      '@sveltejs/site-kit': 3.1.0
       '@types/d3-geo': 3.0.2
       '@types/node': 16.18.6
       flexsearch: 0.7.31
@@ -1323,8 +1323,8 @@ packages:
       picomatch: 2.3.1
       rollup: 3.7.0
 
-  /@sveltejs/site-kit/3.0.3:
-    resolution: {integrity: sha512-zetnU9jGOu+DYcwqpgK9uSUv3qrGrL7JagMN7M8B4bQRoBq1lAPnCvBXtlfQckvkQLtH453JJTIX6ULqL1xtpA==}
+  /@sveltejs/site-kit/3.1.0:
+    resolution: {integrity: sha512-Vv9Efzax+NMRZUfZ9TdUqQYicj2Z3kynLkUUdGPfahjlFEwQ3EGyj1vVCg5jxyqvNUgOsVVUb35nXI5CPsmCfA==}
     dev: true
 
   /@sveltejs/vite-plugin-svelte/2.0.0_svelte@3.55.1+vite@4.0.4:
diff --git a/sites/kit.svelte.dev/package.json b/sites/kit.svelte.dev/package.json
index 6b1828cc4..a374c460c 100644
--- a/sites/kit.svelte.dev/package.json
+++ b/sites/kit.svelte.dev/package.json
@@ -13,7 +13,7 @@
 		"@sveltejs/adapter-vercel": "workspace:^1.0.4",
 		"@sveltejs/amp": "workspace:^",
 		"@sveltejs/kit": "workspace:^",
-		"@sveltejs/site-kit": "^3.0.3",
+		"@sveltejs/site-kit": "^3.1.0",
 		"@types/d3-geo": "^3.0.2",
 		"@types/node": "^16.18.6",
 		"flexsearch": "^0.7.31",
diff --git a/sites/kit.svelte.dev/src/lib/search/content.server.js b/sites/kit.svelte.dev/src/lib/search/content.server.js
index f4d30d1c8..5a22e1858 100644
--- a/sites/kit.svelte.dev/src/lib/search/content.server.js
+++ b/sites/kit.svelte.dev/src/lib/search/content.server.js
@@ -88,7 +88,7 @@ function plaintext(markdown) {
 	const inline = (text) => text;
 
 	return transform(markdown, {
-		code: block,
+		code: (source) => source.split('// ---cut---\n').pop(),
 		blockquote: block,
 		html: (html) => {
 			return html;
diff --git a/sites/kit.svelte.dev/src/routes/+layout.svelte b/sites/kit.svelte.dev/src/routes/+layout.svelte
index 1f59c50b2..441e2658e 100644
--- a/sites/kit.svelte.dev/src/routes/+layout.svelte
+++ b/sites/kit.svelte.dev/src/routes/+layout.svelte
@@ -11,7 +11,6 @@
 	import Search from '$lib/search/Search.svelte';
 	import SearchBox from '$lib/search/SearchBox.svelte';
 	import Logo from './home/svelte-logo.svg';
-	import Banner from './Banner.svelte';
 </script>
 
 <Icons />
@@ -22,8 +21,6 @@
 
 <SkipLink href="#main" />
 
-<Banner />
-
 <Nav {page} logo={Logo}>
 	<svelte:fragment slot="nav-center">
 		{#if $page.url.pathname !== '/search'}
diff --git a/sites/kit.svelte.dev/src/routes/Banner.svelte b/sites/kit.svelte.dev/src/routes/Banner.svelte
deleted file mode 100644
index 66ddc5422..000000000
--- a/sites/kit.svelte.dev/src/routes/Banner.svelte
+++ /dev/null
@@ -1,69 +0,0 @@
-<script>
-	// mimic nav behaviour
-	let last_scroll = 0;
-	let visible = true;
-
-	function handle_scroll() {
-		const scroll = window.pageYOffset;
-		visible = scroll < 50 || scroll < last_scroll;
-
-		last_scroll = scroll;
-	}
-</script>
-
-<svelte:window on:scroll={handle_scroll} />
-
-<header class="banner" class:visible>
-	<p>
-		<a href="https://svelte.dev/blog/announcing-sveltekit-1.0">
-			<strong>SvelteKit 1.0 is here!</strong>
-			<span class="small">Learn more</span>
-			<span class="large">Read the blog post to learn more</span>
-		</a>
-	</p>
-</header>
-
-<style>
-	.banner {
-		position: fixed;
-		top: 0;
-		left: 0;
-		width: 100%;
-		height: 4rem;
-		display: flex;
-		background: var(--sk-theme-1);
-		color: white;
-		z-index: 999;
-		transition: transform 0.2s;
-	}
-
-	.banner p {
-		flex: 1;
-		text-align: center;
-		margin: 1rem;
-	}
-
-	.banner a {
-		color: inherit;
-	}
-
-	.large {
-		display: none;
-	}
-
-	@media (min-width: 440px) {
-		.small {
-			display: none;
-		}
-
-		.large {
-			display: initial;
-		}
-	}
-
-	@media (max-width: 800px) {
-		.banner:not(.visible) {
-			transform: translate(0, calc(-100% - 1rem));
-		}
-	}
-</style>
diff --git a/sites/kit.svelte.dev/src/routes/docs/[slug]/OnThisPage.svelte b/sites/kit.svelte.dev/src/routes/docs/[slug]/OnThisPage.svelte
index f2310bf61..32ba78efd 100644
--- a/sites/kit.svelte.dev/src/routes/docs/[slug]/OnThisPage.svelte
+++ b/sites/kit.svelte.dev/src/routes/docs/[slug]/OnThisPage.svelte
@@ -44,7 +44,7 @@
 			return heading.getBoundingClientRect().top - parseFloat(style.scrollMarginTop) - top;
 		});
 
-		height = window.innerHeight - 50 /* bottom banner height */;
+		height = window.innerHeight;
 	}
 
 	function highlight() {


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 402bc60cf..3f76f2cf9 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,5 +17,6 @@
 <h1>prevent navigation</h1>
 <a href="/before-navigate/a">a</a>
 <a href="/before-navigate/redirect">redirect</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/client.test.js b/packages/kit/test/apps/basics/test/client.test.js
index e71c8db88..f4fa88f80 100644
--- a/packages/kit/test/apps/basics/test/client.test.js
+++ b/packages/kit/test/apps/basics/test/client.test.js
@@ -184,6 +184,16 @@ test.describe('beforeNavigate', () => {
 		expect(page.url()).toBe(baseURL + '/before-navigate/prevent-navigation');
 		expect(await page.innerHTML('pre')).toBe('1 false link');
 	});
+
+	test('is not triggered on target=_blank', async ({ page, baseURL }) => {
+		await page.goto('/before-navigate/prevent-navigation');
+
+		await page.click('a[href="https://google.com"]');
+		await page.waitForTimeout(500);
+
+		expect(page.url()).toBe(baseURL + '/before-navigate/prevent-navigation');
+		expect(await page.innerHTML('pre')).toBe('0 false undefined');
+	});
 });
 
 test.describe('Scrolling', () => {