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#
- Open the reproduction; it runs automatically.
- Each case stores a broken entry followed by a valid query, then calls restoreQueries() or persisterGc().
- 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.