#7893·tldraw

Add waitForSync method to TLSyncClient

Author: MitjaBezensekCreated Feb 12, 2026Updated Sep 28, 2026
Labelssdk

Problem

When using TLSyncClient from Node.js (e.g. for long-running agents interacting with a canvas via WebSockets), there's no way to know when local changes have been acknowledged by the server. This matters for two scenarios:

  1. Before making a server request: the client needs to ensure its writes are synced so the server doesn't read stale data
  2. Before disconnecting: the server-side client needs to ensure all changes are flushed before closing the connection

Currently, TLSyncClient tracks pendingPushRequests and unsentChanges internally but doesn't expose any completion signal. Changes are throttled via FpsScheduler and acknowledged via push_result messages, but consumers can't await this cycle.

Proposed solution

Add a waitForSync(): Promise<void> method that resolves once all currently pending changes (both unsent/buffered and sent-but-unacknowledged) have been acknowledged by the server. Resolves immediately if nothing is pending.

A community member has implemented this as a local patch: https://gist.github.com/mbullington/19b8cad2416341488f7a2350daa680d3

The approach:

  • Track lastAcknowledgedClientClock (updated when push_result is received during rebase)
  • Determine the target clock: this.clientClock if there are unsent changes, or the last pending request's clock otherwise
  • If already acknowledged, resolve immediately
  • Otherwise, queue a listener that resolves when that clock is acknowledged
typescript
store.put([myNewShape])
await syncClient.waitForSync()
// all changes acknowledged by server

Use cases

  • Node.js agents that write to a tldraw room and need to confirm persistence before proceeding
  • Server-side sync clients that need to flush before disconnecting
  • Any programmatic workflow where fire-and-forget isn't sufficient

References