You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Server-side version of query.set() to avoid re-calling the query function when unnecessary (#14304)
* expose query.set
* changeset
* Make query.set() work on server
* changeset
* Update .changeset/social-hats-hope.md
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
* docs
* simplify
* tweaks
* docs
* Update documentation/docs/20-core-concepts/60-remote-functions.md
* remove mentions from docs
* fix
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
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.
162
162
163
-
### Updating queries
163
+
### Refreshing queries
164
164
165
165
Any query can be re-fetched via its `refresh` method, which retrieves the latest value from the server:
166
166
@@ -170,29 +170,6 @@ Any query can be re-fetched via its `refresh` method, which retrieves the latest
170
170
</button>
171
171
```
172
172
173
-
Alternatively, if you need to update its value manually, you can use the `set` method:
174
-
175
-
```svelte
176
-
<script>
177
-
import { getPosts } from'./data.remote';
178
-
import { onMount } from'svelte';
179
-
180
-
onMount(() => {
181
-
constws=newWebSocket('/ws');
182
-
ws.addEventListener('message', (ev) => {
183
-
constmessage=JSON.parse(ev.data);
184
-
if (message.type==='new-post') {
185
-
getPosts().set([
186
-
message.post,
187
-
...getPosts().current,
188
-
]);
189
-
}
190
-
});
191
-
return () =>ws.close();
192
-
});
193
-
</script>
194
-
```
195
-
196
173
> [!NOTE] Queries are cached while they're on the page, meaning `getPosts() ===getPosts()`. This means you don't need a reference like `constposts=getPosts()` in order to update the query.
* On the client, this function will update the value of the query without re-fetching it.
1809
1809
*
1810
-
* On the server, this throws an error.
1810
+
* 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.
1811
+
* This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
* On the client, this function will update the value of the query without re-fetching it.
1785
1785
*
1786
-
* On the server, this throws an error.
1786
+
* 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.
1787
+
* This prevents SvelteKit needing to refresh all queries on the page in a second server round-trip.
0 commit comments