Hi everyone! I'm using TanStack DB in a Chrome Extension environment. Since browser.storage.local is asynchronous, I've implemented a custom storage adapter with a memory cache and an event bridge to make it compatible with the synchronous requirements of localStorageCollectionOptions.
Here is my current implementation strategy:
Initial Hydration: I await browser.storage.local.get during initialization to populate a memory cache object.
Synchronous Adapter: The extensionStorage object (passed to the storage option) reads/writes to this cache synchronously while firing fire-and-forget async updates to the real storage.
Event Bridge: I use browser.storage.onChanged to intercept changes from other contexts (background/popup) and manually trigger the handler by mocking a StorageEvent object.
While this works and successfully triggers useLiveQuery across different tabs/popups, mocking StorageEvent and manual cache management feels a bit hacky.
Is there a recommended "best practice" or a more idiomatic way to handle non-window-localStorage environments in TanStack DB? Specifically, I'd love to know if there's a cleaner way to implement storageEventApi without so much type casting (as any) or event mocking.
Thanks in advance!