-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Open
Description
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.1Severity
annoyance
Metadata
Metadata
Assignees
Labels
No labels