Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,11 @@ Now simply call `addLike`, from (for example) an event handler:

> [!NOTE] Commands cannot be called during render.

### Single-flight mutations
### Updating queries

To update `getLikes(item.id)`, or any other query, we need to tell SvelteKit _which_ queries need to be refreshed (unlike `form`, which by default invalidates everything, to approximate the behaviour of a native form submission).

As with forms, any queries on the page (such as `getLikes(item.id)` in the example above) will automatically be refreshed following a successful command. But we can make things more efficient by telling SvelteKit which queries will be affected by the command, either inside the command itself...
We either do that inside the command itself...

```js
/// file: likes.remote.js
Expand Down
34 changes: 22 additions & 12 deletions apps/svelte.dev/content/docs/kit/98-reference/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -1600,13 +1600,17 @@ Information about the target of a specific navigation.
<div class="ts-block">

```dts
interface NavigationTarget {/*…*/}
interface NavigationTarget<
Params extends
AppLayoutParams<'/'> = AppLayoutParams<'/'>,
RouteId extends AppRouteId | null = AppRouteId | null
> {/*…*/}
```

<div class="ts-block-property">

```dts
params: Record<string, string> | null;
params: Params | null;
```

<div class="ts-block-property-details">
Expand All @@ -1630,7 +1634,7 @@ Info about the target route
<div class="ts-block-property-children"><div class="ts-block-property">

```dts
id: string | null;
id: RouteId | null;
```

<div class="ts-block-property-details">
Expand Down Expand Up @@ -1928,14 +1932,16 @@ The return value of a remote `command` function. See [Remote functions](/docs/ki
<div class="ts-block">

```dts
type RemoteCommand<Input, Output> = (arg: Input) => Promise<
Awaited<Output>
> & {
updates(
...queries: Array<
RemoteQuery<any> | RemoteQueryOverride
>
): Promise<Awaited<Output>>;
type RemoteCommand<Input, Output> = {
(arg: Input): Promise<Awaited<Output>> & {
updates(
...queries: Array<
RemoteQuery<any> | RemoteQueryOverride
>
): Promise<Awaited<Output>>;
};
/** The number of pending command executions */
get pending(): number;
};
```

Expand Down Expand Up @@ -1991,6 +1997,8 @@ type RemoteForm<Result> = {
): Omit<RemoteForm<Result>, 'for'>;
/** The result of the form submission */
get result(): Result | undefined;
/** The number of pending submissions */
get pending(): number;
/** Spread this onto a `<button>` or `<input type="submit">` */
buttonProps: {
type: 'submit';
Expand All @@ -2016,6 +2024,8 @@ type RemoteForm<Result> = {
formaction: string;
onclick: (event: Event) => void;
};
/** The number of pending submissions */
get pending(): number;
};
};
```
Expand Down Expand Up @@ -2050,7 +2060,7 @@ type RemoteQuery<T> = RemoteResource<T> & {
*/
refresh(): Promise<void>;
/**
* Temporarily override the value of a query. This is used with the `updates` method of a [command](https://svelte.dev/docs/kit/remote-functions#command-Single-flight-mutations) or [enhanced form submission](https://svelte.dev/docs/kit/remote-functions#form-enhance) to provide optimistic updates.
* Temporarily override the value of a query. This is used with the `updates` method of a [command](https://svelte.dev/docs/kit/remote-functions#command-Updating-queries) or [enhanced form submission](https://svelte.dev/docs/kit/remote-functions#form-enhance) to provide optimistic updates.
*
* ```svelte
* <script>
Expand Down