Skip to content

Commit 473eef5

Browse files
authored
Merge branch 'main' into repl-legacy-compat
2 parents 2ae1e8b + a89ea32 commit 473eef5

File tree

5 files changed

+70
-38
lines changed

5 files changed

+70
-38
lines changed

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

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export const getPost = query(v.string(), async (slug) => {
161161
162162
Both the argument and the return value are serialized with [devalue](https://github.com/sveltejs/devalue), which handles types like `Date` and `Map` (and custom types defined in your [transport hook](hooks#Universal-hooks-transport)) in addition to JSON.
163163
164-
### Updating queries
164+
### Refreshing queries
165165
166166
Any query can be re-fetched via its `refresh` method, which retrieves the latest value from the server:
167167
@@ -171,29 +171,6 @@ Any query can be re-fetched via its `refresh` method, which retrieves the latest
171171
</button>
172172
```
173173
174-
Alternatively, if you need to update its value manually, you can use the `set` method:
175-
176-
```svelte
177-
<script>
178-
import { getPosts } from './data.remote';
179-
import { onMount } from 'svelte';
180-
181-
onMount(() => {
182-
const ws = new WebSocket('/ws');
183-
ws.addEventListener('message', (ev) => {
184-
const message = JSON.parse(ev.data);
185-
if (message.type === 'new-post') {
186-
getPosts().set([
187-
message.post,
188-
...getPosts().current,
189-
]);
190-
}
191-
});
192-
return () => ws.close();
193-
});
194-
</script>
195-
```
196-
197174
> [!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.
198175
199176
## form
@@ -294,6 +271,9 @@ import * as v from 'valibot';
294271
import { error, redirect } from '@sveltejs/kit';
295272
import { query, form } from '$app/server';
296273
const slug = '';
274+
const post = { id: '' };
275+
/** @type {any} */
276+
const externalApi = '';
297277
// ---cut---
298278
export const getPosts = query(async () => { /* ... */ });
299279

@@ -309,6 +289,15 @@ export const createPost = form(async (data) => {
309289
// Redirect to the newly created page
310290
redirect(303, `/blog/${slug}`);
311291
});
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+
});
312301
```
313302
314303
The second is to drive the single-flight mutation from the client, which we'll see in the section on [`enhance`](#form-enhance).
@@ -565,6 +554,9 @@ export const addLike = command(v.string(), async (id) => {
565554
`;
566555

567556
+++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
568560
});
569561
```
570562

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,8 @@ type RemoteQuery<T> = RemoteResource<T> & {
21942194
/**
21952195
* On the client, this function will update the value of the query without re-fetching it.
21962196
*
2197-
* On the server, this throws an error.
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.
21982199
*/
21992200
set(value: T): void;
22002201
/**

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)