Commit Graph
10 Commits
Author SHA1 Message Date
aksdb cb9e250f6a ♻️ Coalesce realtime changes and stay quiet offline
Every PocketBase event ran its own full sync of the collection, with
rejections nobody caught and around beforeSync and onSyncRound. A
remote change now starts a round through syncNow(), at most one per
300 ms window; one that lands while a round runs gets its own round
after it. The debounced local push is unchanged.

A failed pull or push no longer sets the sync error while the browser
is offline, since the layout shows "Offline" then. A failed round
reports the distinct errors of its syncs on one line instead of the
heading syncAll() puts above them.
2026-12-01 19:08:57 +01:00
aksdb d5b21c431e 🐛 Surface storage errors and ignore a late gate resolution
When IndexedDB rejected or blocked the open, resolveGate() rejected,
the gate stayed null and the app showed "Loading…" forever. A failed
open now cleans up and rejects with a reason, a blocked open gives up
after eight seconds, and resolveGate() turns that into an error gate:
the layout shows the message with a Retry button instead of the loading
line, and the sign-in itself is kept.

logout() clears the auth store and the session before it closes and
wipes the local data, and swallows a failing wipe, so the user is never
left half logged out. activate() sets the session only after the
database is open and only if the auth store is still valid with the
same token, so a resolution that finishes after a logout or another
sign-in no longer reopens the app for the wrong user. openDb() hands
out an in-flight open only to the same user; another user's open waits
for it and then replaces it.
2026-12-01 19:07:11 +01:00
aksdb d387854329 🐛 Merge entry edits after pending sync data has landed
update() read the record before save() waited for the sync to apply
server state, and the record finally written was that stale read plus
the patch with a fresh client_updated_at: an edit silently reverted
what another device had changed in between, and the server took it as
the newer version.

update() and remove() now patch the record after the wait, so every
field they do not touch keeps the value the pull just applied. The
test holds an update while a round applies a remote change to the same
record and fails on the old code with the reverted field.
2026-12-01 19:04:50 +01:00
aksdb d750b8c3c9 🐛 Recover the app when the session expires
A 401 mid-session made the PocketBase SDK drop the auth store, while
session.userId and the gate of the layout stayed set: the user remained
in the app, every round failed, /login was bounced back and a token-less
pull was even taken for a successful round.

The sync layer now ends the session through an onSessionExpired hook
when a round fails with 401 or finds the auth store cleared, and reports
no round as synced without a valid auth store. The session module tries
one token refresh before it clears the session, and the layout resolves
the gate again whenever the auth store is no longer valid, so the user
lands on the login page and the next sign-in brings the data back.
2026-12-01 19:04:06 +01:00
aksdb e630f9fd66 ♻️ Drop legacy browser storage on sign-in
Browsers of users of the Dexie based version still hold its token in
the auth_token key of localStorage and its database named wotra, next
to the per user databases of this version. resolveGate() now removes
both whenever it lets the user into the app, the first open included.
The removal resolves on success, error and block, like wipeLocal, and
never throws, so a browser that denies storage cannot keep the user
out.
2026-12-01 18:07:31 +01:00
aksdb bddabbf93d 🐛 Surface changes rejected by the server
The server now answers an invalid change per item instead of failing
the whole batch, and the client dropped such a change silently: the
round went through and nothing told the user that the edit never
reached the server. A rejected change now sets the sync status to
"<collection>: <error>", cut to 200 characters, so the sync button
shows its warning state. The change is not retried, as before.

The message survives the collections that still succeed in the same
round, since each of them used to clear the error. The next round
without a rejection clears it.
2026-12-01 17:59:29 +01:00
aksdb 6ce66f81c7 🐛 Stop the sync from undoing writes made during a round
The sync manager learns of a local write only from the change record
it creates after the write finished, and it applies the pulled server
state without regard to newer local changes. A write made while a
round was pulling or pushing was therefore replaced by the older
server version, or removed as unknown to the snapshot, until the next
round pushed it again: a deleted adjustment came back, an edit
reverted, a new row vanished for a moment.

Each pull now waits for the writes in flight on the collection and on
the change records, keeps the server version of items whose change
record the round did not push, and local writes wait while the sync
applies server state to their collection; network requests stay
exempt. The stress test writes to four collections for 300 rounds,
with the sync idle and with a push held in flight, and asserts that
reactive and plain reads always show the last write. Without the fix
it fails in the first round.
2026-12-01 17:56:43 +01:00
aksdb bd2ec79a69 🐛 Silence SignalDB warnings for reads outside reactive scopes
Every read outside a reactive scope passed { reactive: false } and made
Cursor.depend() log a warning. Such reads now use a silent reactivity
adapter, and all, get, pendingCount and save release the cursor again
with cleanup(), so nothing is registered and nothing leaks. Reads inside
$derived or $effect stay reactive as before.

Vitest now resolves the browser export of Svelte. Without it
svelte/reactivity is the server stub, createSubscriber never starts and
no effect re-runs after a write in tests.
2026-12-01 17:02:53 +01:00
aksdb 29f3cb9926 🐛 Push sync changes in batches of 200
The server rejects more than 500 changes per request, so one large
offline batch would otherwise stay pending forever.
2026-11-29 20:16:45 +00:00
aksdb 6a6c2bb71d ✨ Add SignalDB collections synced with PocketBase 2026-11-29 17:21:41 +00:00