fix(query-persist-client-core): catch errors when persisting in 'persistQueryClientSubscribe' to prevent unhandled promise rejections, and log them in development by kazbekaskarov · Pull Request #11678 · TanStack/query · GitHub
Skip to content

fix(query-persist-client-core): catch errors when persisting in 'persistQueryClientSubscribe' to prevent unhandled promise rejections, and log them in development - #11678

Open
kazbekaskarov wants to merge 1 commit into
TanStack:mainfrom
kazbekaskarov:fix/persist-subscribe-unhandled-rejection

Conversation

@kazbekaskarov

@kazbekaskarov kazbekaskarov commented Sep 26, 2026 •

Copy link
Copy Markdown

🎯 Changes

Fixes #11663.

persistQueryClientSubscribe dropped the promise returned by persistQueryClientSave, so a failing persister.persistClient (e.g. QuotaExceededError from IndexedDB) or a throwing dehydrateOptions callback caused an unhandled promise rejection on every cache update.

The subscription now catches these errors and, in development, logs them with console.error + console.warn, consistent with how persistQueryClientRestore reports restore errors.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I have followed the AI contribution policy and fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Persistence errors during query updates are now caught and logged in development, preventing unhandled promise rejections. Errors during dehydration are also reported.

…istQueryClientSubscribe' to prevent unhandled promise rejections, and log them in development
@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

@n-satoshi061

Copy link
Copy Markdown
Contributor

Thanks for picking this up! The fix looks correct to me for both paths (a rejecting persistClient and a throwing dehydrateOptions callback).

One thing that might be worth a maintainer's call: right now, a failed save in production at least surfaces as an unhandled rejection, which error trackers like Sentry pick up via onunhandledrejection. With this change, it's caught and nothing is reported in production, so the failure becomes completely silent there.

That may well be the right tradeoff. I just wanted to point it out, since the restore side isn't silent in production (it calls removeClient() and rethrows).

@kazbekaskarov

Copy link
Copy Markdown
Author

This branch has not been deployed

No deployments
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.

persistQueryClientSubscribe drops the persistQueryClientSave promise, causing unhandled rejections when persisting fails

2 participants