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:
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) {
|
||||
|
||||
Reference in new issue
Block a user