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
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.
163
163
164
-
### Updating queries
164
+
### Refreshing queries
165
165
166
166
Any query can be re-fetched via its `refresh` method, which retrieves the latest value from the server:
167
167
@@ -171,29 +171,6 @@ Any query can be re-fetched via its `refresh` method, which retrieves the latest
171
171
</button>
172
172
```
173
173
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
-
constws=newWebSocket('/ws');
183
-
ws.addEventListener('message', (ev) => {
184
-
constmessage=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
-
197
174
> [!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.
Copy file name to clipboardExpand all lines: apps/svelte.dev/content/docs/kit/98-reference/[email protected]
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2194,7 +2194,8 @@ type RemoteQuery<T> = RemoteResource<T> & {
2194
2194
/**
2195
2195
* On the client, this function will update the value of the query without re-fetching it.
2196
2196
*
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.
0 commit comments