Skip to content

Remote functions - withOverride optimistic updates require 2 ticks #17472

@alexiglesias93

Description

@alexiglesias93

Describe the bug

I'm implementing optimistic updates using remote functions, and while playing around with document.startWithTransition I've noticed that I need to wait 2 Svelte ticks for the transition snapshot to be taken correctly.

Not sure if this is expected or a bug!

Reproduction

Using the following example, waiting for a single tick will not guarantee that the DOM is updated after firing an optimistic update:

	const handle_delete_member = () => {
		document.startViewTransition(async () => {
			const override = get_members().withOverride((members) =>
				members.filter((m) => m.id !== member.id)
			);

			delete_member(member.id).updates(override).catch(console.error);

			await tick();
		});
	};

The view transition doesn't run correctly because I assume that the new snapshot doesn't contain the optimistic updates yet:

1.tick.mp4

But if I wait for 2 ticks, then the snapshot seems to be correct and the view transition runs as expected:

	const handle_delete_member = () => {
		document.startViewTransition(async () => {
			const override = get_members().withOverride((members) =>
				members.filter((m) => m.id !== member.id)
			);

			delete_member(member.id).updates(override).catch(console.error);

			await tick();
+			await tick();
		});
	};
2.ticks.mp4

Logs

System Info

System:
    OS: macOS 15.7.3
    CPU: (8) arm64 Apple M3
    Memory: 524.06 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.12.0 - /Users/alexiglesiaspinol/.nvm/versions/node/v24.12.0/bin/node
    npm: 11.6.2 - /Users/alexiglesiaspinol/.nvm/versions/node/v24.12.0/bin/npm
    pnpm: 10.28.0 - /Users/alexiglesiaspinol/Library/pnpm/pnpm
  Browsers:
    Chrome: 143.0.7499.193
    Firefox: 143.0.4
    Safari: 18.6
  npmPackages:
    svelte: ^5.45.6 => 5.46.1

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions