Skip to content

Commit 6260612

Browse files
authored
Merge branch 'main' into fix-console-scroll
2 parents 3d5a777 + a89ea32 commit 6260612

File tree

5 files changed

+76
-15
lines changed

5 files changed

+76
-15
lines changed

apps/svelte.dev/content/docs/kit/20-core-concepts/60-remote-functions.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ Both the argument and the return value are serialized with [devalue](https://git
163163
164164
### Refreshing queries
165165
166-
Any query can be updated via its `refresh` method:
166+
Any query can be re-fetched via its `refresh` method, which retrieves the latest value from the server:
167167
168168
```svelte
169169
<button onclick={() => getPosts().refresh()}>
170170
Check for new posts
171171
</button>
172172
```
173173
174-
> [!NOTE] Queries are cached while they're on the page, meaning `getPosts() === getPosts()`. This means you don't need a reference like `const posts = getPosts()` in order to refresh the query.
174+
> [!NOTE] Queries are cached while they're on the page, meaning `getPosts() === getPosts()`. This means you don't need a reference like `const posts = getPosts()` in order to update the query.
175175
176176
## form
177177
@@ -271,6 +271,9 @@ import * as v from 'valibot';
271271
import { error, redirect } from '@sveltejs/kit';
272272
import { query, form } from '$app/server';
273273
const slug = '';
274+
const post = { id: '' };
275+
/** @type {any} */
276+
const externalApi = '';
274277
// ---cut---
275278
export const getPosts = query(async () => { /* ... */ });
276279

@@ -286,6 +289,15 @@ export const createPost = form(async (data) => {
286289
// Redirect to the newly created page
287290
redirect(303, `/blog/${slug}`);
288291
});
292+
293+
export const updatePost = form(async (data) => {
294+
// form logic goes here...
295+
const result = externalApi.update(post);
296+
297+
// The API already gives us the updated post,
298+
// no need to refresh it, we can set it directly
299+
+++await getPost(post.id).set(result);+++
300+
});
289301
```
290302
291303
The second is to drive the single-flight mutation from the client, which we'll see in the section on [`enhance`](#form-enhance).
@@ -542,6 +554,9 @@ export const addLike = command(v.string(), async (id) => {
542554
`;
543555

544556
+++getLikes(id).refresh();+++
557+
// Just like within form functions you can also do
558+
// getLikes(id).set(...)
559+
// in case you have the result already
545560
});
546561
```
547562

apps/svelte.dev/content/docs/kit/98-reference/[email protected]

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,13 @@ type RemotePrerenderFunction<Input, Output> = (
21912191

21922192
```dts
21932193
type RemoteQuery<T> = RemoteResource<T> & {
2194+
/**
2195+
* On the client, this function will update the value of the query without re-fetching it.
2196+
*
2197+
* On the server, this can be called in the context of a `command` or `form` and the specified data will accompany the action response back to the client.
2198+
* This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
2199+
*/
2200+
set(value: T): void;
21942201
/**
21952202
* On the client, this function will re-fetch the query from the server.
21962203
*

apps/svelte.dev/content/docs/kit/98-reference/50-configuration.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ This is useful for allowing trusted third-party services like payment gateways o
289289

290290
If the array contains `'*'`, all origins will be trusted. This is generally not recommended!
291291

292-
**Warning**: Only add origins you completely trust, as this bypasses CSRF protection for those origins.
292+
> [!NOTE] Only add origins you completely trust, as this bypasses CSRF protection for those origins.
293+
294+
CSRF checks only apply in production, not in local development.
293295

294296
</div>
295297
</div>

apps/svelte.dev/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@supabase/supabase-js": "^2.43.4",
5353
"@sveltejs/adapter-vercel": "^5.10.2",
5454
"@sveltejs/enhanced-img": "^0.8.1",
55-
"@sveltejs/kit": "^2.34.0",
55+
"@sveltejs/kit": "^2.37.0",
5656
"@sveltejs/site-kit": "workspace:*",
5757
"@sveltejs/vite-plugin-svelte": "^6.1.3",
5858
"@types/cookie": "^0.6.0",

pnpm-lock.yaml

Lines changed: 48 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)