SessionLock is a pluggable, single-active-session guard used by the offline
persistence path. Offline persistence derives a stable actor from the app's
clientKey, so two browser tabs of the same app+user share that actor. Two live
tabs would then share one server checkpoint and mint colliding clientSeq
values — silent edit loss. The guard elects a single active session per
document key so the second tab fails fast instead of corrupting the store.
The abstraction is injectable so it can be tested without a real browser: the
default WebLocksSessionLock is backed by the Web Locks API, and tests
pass an in-memory fake.
acquire tries to acquire the lock named name without waiting. It
resolves with a SessionLockHandle when the lock was acquired, or
undefined when it is already held elsewhere (e.g. by another tab) — the
caller treats undefined as fail-fast.
SessionLockis a pluggable, single-active-session guard used by the offline persistence path. Offline persistence derives a stable actor from the app's clientKey, so two browser tabs of the same app+user share that actor. Two live tabs would then share one server checkpoint and mint collidingclientSeqvalues — silent edit loss. The guard elects a single active session per document key so the second tab fails fast instead of corrupting the store.The abstraction is injectable so it can be tested without a real browser: the default WebLocksSessionLock is backed by the Web Locks API, and tests pass an in-memory fake.