Skip to content

Commit b4e4b7a

Browse files
Fix docs (#15781)
extracted from sveltejs/svelte.dev#1959 --------- Co-authored-by: Tee Ming <[email protected]>
1 parent a416bb0 commit b4e4b7a

7 files changed

Lines changed: 37 additions & 10 deletions

File tree

documentation/docs/20-core-concepts/60-remote-functions.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,14 @@ In addition to declarative schema validation, you can programmatically mark fiel
562562
- It accepts multiple arguments that can be strings (for issues relating to the form as a whole — these will only show up in `fields.allIssues()`) or standard-schema-compliant issues (for those relating to a specific field). Use the `issue` parameter for type-safe creation of such issues:
563563
564564
```js
565+
// @errors: 18046
565566
/// file: src/routes/shop/data.remote.js
567+
// @filename: ambient.d.ts
568+
declare module '$lib/server/database' {
569+
export function buy(qty: number): Promise<void>
570+
}
571+
// @filename: index.js
572+
// ---cut---
566573
import * as v from 'valibot';
567574
import { invalid } from '@sveltejs/kit';
568575
import { form } from '$app/server';
@@ -1227,7 +1234,7 @@ As long as _you're_ not passing invalid data to your remote functions, there are
12271234
In the second case, we don't want to give the attacker any help, so SvelteKit will generate a generic [400 Bad Request](https://http.dog/400) response. You can control the message by implementing the [`handleValidationError`](hooks#Server-hooks-handleValidationError) server hook, which, like [`handleError`](hooks#Shared-hooks-handleError), must return an [`App.Error`](errors#Type-safety) (which defaults to `{ message: string }`):
12281235
12291236
```js
1230-
/// file: src/hooks.server.ts
1237+
/// file: src/hooks.server.js
12311238
/** @type {import('@sveltejs/kit').HandleValidationError} */
12321239
export function handleValidationError({ event, issues }) {
12331240
return {
@@ -1253,14 +1260,26 @@ export const getStuff = query('unchecked', async ({ id }: { id: string }) => {
12531260
Inside `query`, `form` and `command` you can use [`getRequestEvent`]($app-server#getRequestEvent) to get the current [`RequestEvent`](@sveltejs-kit#RequestEvent) object. This makes it easy to build abstractions for interacting with cookies, for example:
12541261
12551262
```ts
1256-
/// file: user.remote.ts
1263+
/// file: user.remote.js
1264+
// @filename: ambient.d.ts
1265+
interface User {
1266+
name: string;
1267+
avatar: string;
1268+
}
1269+
1270+
declare module '$lib/server/database' {
1271+
export function findUser(sessionId: string | undefined): Promise<User | null>;
1272+
}
1273+
1274+
// @filename: index.js
1275+
// ---cut---
12571276
import { getRequestEvent, query } from '$app/server';
12581277
import { findUser } from '$lib/server/database';
12591278

12601279
export const getProfile = query(async () => {
12611280
const user = await getUser();
12621281

1263-
return {
1282+
return user && {
12641283
name: user.name,
12651284
avatar: user.avatar
12661285
};

documentation/docs/25-build-and-deploy/50-adapter-static.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This will prerender your entire site as a collection of static files. If you'd l
1111
Install with `npm i -D @sveltejs/adapter-static`, then add the adapter to your `svelte.config.js`:
1212

1313
```js
14+
// @errors: 2307
1415
/// file: svelte.config.js
1516
import adapter from '@sveltejs/adapter-static';
1617

@@ -55,6 +56,7 @@ Some platforms have zero-config support (more to come in future):
5556
On these platforms, you should omit the adapter options so that `adapter-static` can provide the optimal configuration:
5657

5758
```js
59+
// @errors: 2307
5860
/// file: svelte.config.js
5961
import adapter from '@sveltejs/adapter-static';
6062

@@ -80,7 +82,7 @@ The directory to write static assets (the contents of `static`, plus client-side
8082

8183
### fallback
8284

83-
To create a [single page app (SPA)](single-page-apps) you must specify the name of the fallback page to be generated by SvelteKit, which is used as the entry point for URLs that have not been prerendered. This is commonly `200.html`, but can vary depending on your deployment platform. You should avoid `index.html` where possible to avoid conflicting with a prerendered homepage.
85+
To create a [single page app (SPA)](single-page-apps) you must specify the name of the fallback page to be generated by SvelteKit, which is used as the entry point for URLs that have not been prerendered. This is commonly `200.html`, but can vary depending on your deployment platform. You should avoid `index.html` where possible to avoid conflicting with a prerendered homepage.
8486

8587
> [!NOTE] This option has large negative performance and SEO impacts. It is only recommended in certain circumstances such as wrapping the site in a mobile app. See the [single page apps](single-page-apps) documentation for more details and alternatives.
8688
@@ -101,7 +103,7 @@ You'll also want to generate a fallback `404.html` page to replace the default 4
101103
A config for GitHub Pages might look like the following:
102104

103105
```js
104-
// @errors: 2322
106+
// @errors: 2307 2322
105107
/// file: svelte.config.js
106108
import adapter from '@sveltejs/adapter-static';
107109

documentation/docs/25-build-and-deploy/55-single-page-apps.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const ssr = false;
1919
If you don't have any server-side logic (i.e. `+page.server.js`, `+layout.server.js` or `+server.js` files) you can use [`adapter-static`](adapter-static) to create your SPA. Install `adapter-static` with `npm i -D @sveltejs/adapter-static` and add it to your `svelte.config.js` with the `fallback` option:
2020

2121
```js
22+
// @errors: 2307
2223
/// file: svelte.config.js
2324
import adapter from '@sveltejs/adapter-static';
2425

documentation/docs/25-build-and-deploy/60-adapter-cloudflare.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This adapter will be installed by default when you use [`adapter-auto`](adapter-
1717
Install with `npm i -D @sveltejs/adapter-cloudflare`, then add the adapter to your `svelte.config.js`:
1818

1919
```js
20+
// @errors: 2307
2021
/// file: svelte.config.js
2122
import adapter from '@sveltejs/adapter-cloudflare';
2223

documentation/docs/25-build-and-deploy/80-adapter-netlify.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This adapter will be installed by default when you use [`adapter-auto`](adapter-
1111
Install with `npm i -D @sveltejs/adapter-netlify`, then add the adapter to your `svelte.config.js`:
1212

1313
```js
14+
// @errors: 2307
1415
/// file: svelte.config.js
1516
import adapter from '@sveltejs/adapter-netlify';
1617

@@ -53,6 +54,7 @@ New projects will use the current Node LTS version by default. However, if you'r
5354
SvelteKit supports [Netlify Edge Functions](https://docs.netlify.com/build/edge-functions/overview/). If you pass the option `edge: true` to the `adapter` function, server-side rendering will happen in a Deno-based edge function that's deployed close to the site visitor. If set to `false` (the default), the site will deploy to Node-based Netlify Functions.
5455

5556
```js
57+
// @errors: 2307
5658
/// file: svelte.config.js
5759
import adapter from '@sveltejs/adapter-netlify';
5860

documentation/docs/30-advanced/68-observability.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ To view your first trace, you'll need to set up a local collector. We'll use [Ja
7474
- Create `src/instrumentation.server.js` with the following:
7575

7676
```js
77+
// @errors: 2307
7778
/// file: src/instrumentation.server.js
7879
import { NodeSDK } from '@opentelemetry/sdk-node';
7980
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
@@ -97,4 +98,4 @@ Now, server-side requests will begin generating traces, which you can view in Ja
9798
9899
## `@opentelemetry/api`
99100
100-
SvelteKit uses `@opentelemetry/api` to generate its spans. This is declared as an optional peer dependency so that users not needing traces see no impact on install size or runtime performance. In most cases, if you're configuring your application to collect SvelteKit's spans, you'll end up installing a library like `@opentelemetry/sdk-node` or `@vercel/otel`, which in turn depend on `@opentelemetry/api`, which will satisfy SvelteKit's dependency as well. If you see an error from SvelteKit telling you it can't find `@opentelemetry/api`, it may just be because you haven't set up your trace collection yet. If you _have_ done that and are still seeing the error, you can install `@opentelemetry/api` yourself.
101+
SvelteKit uses `@opentelemetry/api` to generate its spans. This is declared as an optional peer dependency so that users not needing traces see no impact on install size or runtime performance. In most cases, if you're configuring your application to collect SvelteKit's spans, you'll end up installing a library like `@opentelemetry/sdk-node` or `@vercel/otel`, which in turn depend on `@opentelemetry/api`, which will satisfy SvelteKit's dependency as well. If you see an error from SvelteKit telling you it can't find `@opentelemetry/api`, it may just be because you haven't set up your trace collection yet. If you _have_ done that and are still seeing the error, you can install `@opentelemetry/api` yourself.

documentation/docs/40-best-practices/10-accessibility.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ If your content is available in multiple languages, you should set the `lang` at
6565
6666
```js
6767
/// file: src/hooks.server.js
68-
/**
69-
* @param {import('@sveltejs/kit').RequestEvent} event
70-
*/
71-
function get_lang(event) {
68+
// @filename: utils.ts
69+
export function get_lang(event: import('@sveltejs/kit').RequestEvent) {
7270
return 'en';
7371
}
72+
73+
// @filename: hooks.server.js
74+
import { get_lang } from './utils';
7475
// ---cut---
7576
/** @type {import('@sveltejs/kit').Handle} */
7677
export function handle({ event, resolve }) {

0 commit comments

Comments
 (0)