Skip to content

feat(admin): add IndexedDB offline cache and optimistic mutation sync#1156

Closed
bhubbard wants to merge 19 commits into
emdash-cms:mainfrom
bhubbard:indexedDB
Closed

feat(admin): add IndexedDB offline cache and optimistic mutation sync#1156
bhubbard wants to merge 19 commits into
emdash-cms:mainfrom
bhubbard:indexedDB

Conversation

@bhubbard
Copy link
Copy Markdown

What does this PR do?

This PR implements a robust offline caching and synchronization layer in the Admin UI using IndexedDB. It enables instant page rendering by serving cached data as placeholderData before fresh data resolves from the network. It also introduces multi-tab cache invalidation coordination, offline background sync, and resilient optimistic mutations that automatically roll back on error.

Specifically, this includes:

  • IndexedDB caching layer: Abstractions (db.ts, cache-store.ts) for caching singletons, detail records, and list content, with pre-warmup.
  • TanStack Query Integration: The useCachedQuery hook that falls back to the cache instantly and refreshes from the network in the background.
  • Optimistic Mutations: Helpers (optimisticDelete, optimisticUpdate, optimisticListItemUpdate) to immediately update the local query and IndexedDB states, handling query rollbacks on failure.
  • Multi-tab Coordination: BroadcastChannel-based communication to invalidate and sync cache stores across multiple open browser tabs.
  • Offline & Background Sync: Logic for managing offline states and synchronizing pending local changes back to the server once online.
  • Admin UI Integration: Integrated caching/optimistic updates into Admin UI routes and components (Settings, Media, Menus, Taxonomies, Users, and Bylines).
  • Tests: A full suite of unit tests for all caching, synchronization, broadcasting, and mutation features.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added a changeset (if this PR changes a published package)

Note: If you are going to publish these changes, please run pnpm changeset locally before opening the PR to generate the changeset file.

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Gemini

bhubbard and others added 18 commits April 1, 2026 23:50
… (Phases 3 & 4)

- Optimistic delete/update helpers for instant UI feedback with rollback on error
- Background sync manager with visibility-aware polling (pauses when tab hidden)
- Multi-tab cache coordination via BroadcastChannel
- Sync status indicator in header (shows syncing/offline/error states)
- "Clear Local Cache" button in General Settings
- Convert content/media delete, publish/unpublish to optimistic mutations
- Convert menus and sections to use optimistic delete

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CacheProvider calls useQueryClient(), so it needs QueryClientProvider
as an ancestor. The reversed nesting caused the dashboard to hang on
load.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
56 tests across 6 test files covering:
- db.ts: database setup, schema creation, connection lifecycle
- cache-store.ts: CRUD operations, TTL expiry, pruning, index queries
- cache-warmup.ts: singleton pre-loading from IndexedDB
- broadcast.ts: BroadcastChannel multi-tab coordination
- sync.ts: background sync manager lifecycle and status
- optimistic-mutation.ts: optimistic delete/update/rollback

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 24, 2026

🦋 Changeset detected

Latest commit: 5169ebf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@emdash-cms/admin Minor
emdash Minor
@emdash-cms/cloudflare Minor
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/auth Minor
@emdash-cms/blocks Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 Minor
create-emdash Minor
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

Scope check

This PR changes 5,206 lines across 32 files. Large PRs are harder to review and more likely to be closed without review.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@github-actions
Copy link
Copy Markdown
Contributor

PR template validation failed

Please fix the following issues by editing your PR description:

See CONTRIBUTING.md for the full contribution policy.

@bhubbard bhubbard changed the title Indexed db feat(admin): add IndexedDB offline cache and optimistic mutation sync May 24, 2026
@bhubbard bhubbard marked this pull request as draft May 24, 2026 05:01
@bhubbard bhubbard closed this May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant