Building on yesterday's command example, we tackle network latency with optimistic updates. When slow server responses make toggling a list item feel sluggish, we can do better by updating the UI immediately and letting the server catch up.
Chain .updates() to your command call, pass in the query that should update, and call .withOverride() on it. You receive the current state and return what the UI should display right now. The interface responds instantly. Optimistic updates automatically revert when the request completes, whether it succeeds or fails, so if something goes wrong the UI snaps back to the real state. Fast, smooth, and safe.
Read the docs: https://svelte.dev/docs/kit/remote-fu...