Skip to content
Source
Sign inSign up
TanStack/query

restoreQueries and persisterGc throw on malformed persisted entries #11918

ClosedVGontier-cmd(GitHub profile, opens in a new tab) opened this issue 0 comments

Describe the bug

When using experimental_createQueryPersister, restoreQueries() throws if a stored entry contains "null", "{}" or '{"state":null}'. The entry stays in storage and the next valid query is not restored.

persisterGc() also throws on these entries.

With invalid JSON like "not-json{", the entry is removed and processing continues. I would expect the same behavior for these values.

Your minimal, reproducible example

https://stackblitz.com/edit/bqs8bszm?file=index.js

Steps to reproduce

  1. Open the reproduction; it runs automatically.
  2. Each case stores a broken entry followed by a valid query, then calls restoreQueries() or persisterGc().
  3. The invalid JSON cases pass, but "null", "{}" and '{"state":null}' cause a TypeError. For restoreQueries(), the next valid query is not restored.

Expected behavior

The malformed entry should be removed without throwing, and processing should continue with the remaining entries.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: macOS 27.0
  • Browser: Chromium 154.0.8037.98 (verified with Playwright)

Tanstack Query adapter

vanilla

TanStack Query version

5.104.1 for both @tanstack/query-core and @tanstack/query-persist-client-core

TypeScript version

No response

Additional context

The valid query in the reproduction has null as its data. This is intentional: null query data should still be restored correctly.

  1. DogPawHat closed this

Sign in to join this conversation.