8 Commits
Author SHA1 Message Date
Tom Moor 1ca8335717 fix: Recover from closed IndexedDB connections in store persistence (#13523)
* fix: Recover from closed IndexedDB connections in store persistence

StorePersistence cached a single IDBDatabase forever, so once the browser
or another tab closed the connection every subsequent hydrate, flush and
clear threw against a dead handle.

- Close and forget the connection on versionchange, so another tab is
  never blocked from deleting or upgrading the database
- Discard the cached connection on close, open error and blocked, and
  retry once against a fresh connection when one was closed underneath us
- Close open connections before deleteAllDatabases removes them, which
  also stops logout recreating the databases it just deleted

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix: Cancel pending writes when store persistence is disabled

A debounced flush scheduled before disabling would still fire, reopening
and recreating the database that deleteAllDatabases had just removed.
2026-08-22 19:01:39 -04:00
Tom MoorandClaude f668a24663 feat: Persist policies to IndexedDB so abilities survive reload (#13138)
* feat: Persist policies to IndexedDB so abilities survive reload

Adds a StorePersistence layer that caches a store's models in IndexedDB
and hydrates them back at boot as stale data, revalidated by normal API
traffic. Enabled for the policies store, scoped per team, so cached
abilities are available immediately after a reload instead of every
policy needing a forced refetch.

- Persistence hooks in the base Store add/remove/clear methods, since
  add() updates existing models in place and map observation would miss
  those changes
- Enabled from RootStore construction (team read from localStorage) and
  again after auth.info succeeds to cover the first session after login
- Store.clear() wipes the persisted records, covering both logout paths
- deleteAllDatabases() fallback removes the policies database on
  browsers without indexedDB.databases()

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XisV6sRdexfnPSiehurKoV

* refactor: Opt stores into persistence via a persistable property

Stores now declare persistence with `persistable = true` and RootStore
sweeps all persistable stores, deriving each database name from the
store's apiEndpoint, instead of RootStore hard-coding the policies
store. The deleteAllDatabases fallback uses the same sweep.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XisV6sRdexfnPSiehurKoV

* refactor: Simplify store persistence enablement and clearing

- Move the persistable guard into Store.enablePersistence so RootStore
  can call it unconditionally on every store
- StorePersistence derives its own database name from the store and
  teamId rather than receiving a prebuilt name
- StorePersistence.clear returns a promise, making the test deterministic
  instead of sleeping

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XisV6sRdexfnPSiehurKoV

* fix: Avoid re-persisting hydrated records, await clear transaction

Hydration called store.add() for every cached record, which now triggers
persist() and scheduled a flush that wrote the just-loaded data straight
back to IndexedDB at boot. Guard persist() with a hydrating flag.

clear() awaited the objectStore.clear() request rather than the enclosing
transaction, so it could resolve before commit and miss abort errors.

* lock

* iterate

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-08-16 14:13:06 -04:00
Tom Moor 0139b91b5d chore: Replace lodash with es-toolkit (#12281)
* chore: Replace lodash with es-toolkit

Migrate all direct lodash imports to es-toolkit/compat for a smaller,
faster, lodash-compatible utility library. Transitive lodash usage from
other packages remains unchanged.

* fix: Restore isPlainObject semantics in CanCan policy

The lodash migration aliased `isObject` to `lodash/isPlainObject` and
the codemod incorrectly mapped the local name to es-toolkit's `isObject`,
which also returns true for arrays and functions. This caused condition
objects in policy definitions to be skipped, breaking authorization
checks across the codebase.

* fix: Restore unicode-aware length counting in validators

es-toolkit/compat's size() returns string.length, while lodash's _.size()
counts unicode code points. Switch to [...value].length to preserve the
previous behavior so multi-byte characters like emoji count as one.
2026-05-06 21:03:47 -04:00
Tom Moor 0d47c10efc fix: Runtime check for indexeddb (#12028)
* fix: Runtime check for indexeddb access

* PR feedback
2026-04-13 20:29:54 -04:00
Salihu 430883f186 feat: Custom emoji (#10513)
Towards #9278
2025-12-01 02:31:50 +01:00
Tom Moor 9855adcd3b fix: Clear IndexedDB cache command on FF, closes #6821 2024-04-21 20:48:01 -04:00
Tom Moor 89d5527d39 Handle promise linting (#5488) 2023-06-28 17:18:18 -07:00
Tom Moor 15b1069bcc chore: Move to Typescript (#2783)
This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously.

closes #1282
2021-11-29 06:40:55 -08:00