fix(query-cache): guard against undefined result from superjson.parse on legacy cache entries

Fixes #6219

superjson.parse returns undefined when given plain JSON (stored by older
versions before the superjson serializer was introduced). Without the null
guard, accessing .buster on undefined throws "Cannot read properties of
undefined (reading 'buster')", which is caught and logged as
"Failed to hydrate query cache" — contributing to instability on upgrade.

Also remove now-redundant optional chaining on persisted.clientState since
persisted is guaranteed non-null at that point.
This commit is contained in:
ajnart committed 2026-07-06 18:07:52 +02:00
1 parent 24188ce51f
commit 1fe07f8d79
1 file changed
+2 -2
@@ -124,8 +124,8 @@ async function QueryCacheHydration({ userId, boardId }: { userId: string; boardI
if (!serialized) return null;
const persisted = superjson.parse<PersistedClient>(serialized);
if (persisted.buster !== queryCacheBuster) return null;
if (!persisted?.clientState?.queries?.length) return null;
if (!persisted || persisted.buster !== queryCacheBuster) return null;
if (!persisted.clientState?.queries?.length) return null;
return <HydrationBoundary state={persisted.clientState} />;
} catch (error) {