Skip to content

fix(query-cache): keep game data in memory when the IndexedDB cache fails - #555

Merged
jplacht merged 1 commit into
mainfrom
fix/indexeddb-cache-failure
Oct 2, 2026
Merged

jplacht merged 1 commit into
mainfrom
fix/indexeddb-cache-failure

Conversation

@jplacht

@jplacht jplacht commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

What and why

When the browser closes the IndexedDB connection (site data cleared, eviction) or storage is full, every game-data query failed even though the API returned valid data, and plan pages showed a failed loader step until reload (PostHog: InvalidStateError: … connection is closing, QuotaExceededError). The cache is an optimisation, so a broken cache must never fail a query.

Changes

  • storeAndPreload falls back to the in-memory layer (new useDB().fill(rows, replace)) when the IndexedDB write or read-back throws, so the query resolves with the API data. Planet queries (no wipe) upsert into the rows already loaded; full lists replace them.
  • getDB reopens after the browser force-closes the connection (terminated) or after a failed open. storeAndPreload also drops the connection on InvalidStateError / UnknownError (WebKit's lost connection), so one lost without a close event reopens too.
  • setMany awaits every request together with tx.done, so an aborted transaction (e.g. quota) rejects once instead of producing an unhandled rejection per row.
  • Tests for the fallback, upsert vs. replace, reconnects, the abort path and its rollback; docs/data-layer.md updated.

How it was verified

  • pnpm test && pnpm tsc && pnpm lint && pnpm knip: all pass.
  • New tests fail against the old code (reconnect, failed open, unhandled rejections on abort).
  • Independent QA review: PASS, retest after follow-up fixes PASS.
  • Not exercised in the running app: a forced IndexedDB close can't be triggered from the browser on demand.

Closes #549

🤖 Generated with Claude Code

…ails

- storeAndPreload falls back to the in-memory layer (new useDB fill) when
  the IndexedDB write or read-back throws, so the query resolves with the
  API data instead of failing
- getDB reopens after the browser force-closes the connection (terminated)
  or after a failed open; storeAndPreload drops the connection on
  InvalidStateError / UnknownError so a silently lost one reopens too
- setMany awaits every request with tx.done, so an aborted transaction
  (e.g. quota) rejects once instead of leaving unhandled rejections
- tests for the fallback, upsert vs. replace, reconnects and the abort path;
  data-layer docs updated

Closes #549

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for prunplanner-preview ready!

Name Link
🔨 Latest commit 36c5292
🔍 Latest deploy log https://app.netlify.com/projects/prunplanner-preview/deploys/6abf5449b746ab00081997c4
😎 Deploy Preview https://deploy-preview-555--prunplanner-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codacy-production

codacy-production Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 6 complexity · 0 duplication

Metric Results
Complexity 6
Duplication 0

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.01% coverage variation

Metric Results
Coverage variation ✅ +0.01% coverage variation (-1.00%)
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (f0cad6e) 3703 3613 97.57%
Head commit (36c5292) 3714 (+11) 3624 (+11) 97.58% (+0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#555) 20 20 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@jplacht
jplacht merged commit 2dd075e into main Oct 2, 2026
11 checks passed
@jplacht
jplacht deleted the fix/indexeddb-cache-failure branch October 2, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexedDB write failure fails the whole query despite good API data

1 participant