fix(devtools): fix crash with custom queryKeyHashFn and async persistence#10644
fix(devtools): fix crash with custom queryKeyHashFn and async persistence#10644lihan3238 wants to merge 1 commit intoTanStack:mainfrom
Conversation
…ence
When using async persistence (e.g. IndexedDB) combined with a custom
`queryKeyHashFn`, the DevTools would crash with
`TypeError: Cannot read properties of undefined (reading 'fetchStatus')`.
The root cause is that `queryCache.find({ queryKey })` uses the default
`hashQueryKey` internally to match queries, which fails when a custom
`queryKeyHashFn` is configured. Replace these calls with
`queryCache.get(queryHash)` which looks up queries directly by their
already-computed hash, bypassing the hash mismatch issue.
Closes TanStack#6958
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe DevTools query-row component switches from ChangesDevTools Query Lookup
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
When using async persistence (e.g. IndexedDB) combined with a custom
queryKeyHashFn, the DevTools crash on initial load with:The root cause is that
queryCache.find({ queryKey })internally uses the defaulthashQueryKeyto compute the hash and match queries. When a customqueryKeyHashFnis configured, this computed hash won't match the query's actual hash in the cache, sofind()returnsundefined.Fix
Replaced
queryCache.find({ queryKey: props.query.queryKey })calls withqueryCache.get(props.query.queryHash)in the DevTools query detail component. Theget()method looks up queries directly by their already-computed hash string, which correctly finds the query regardless of which hash function was used.The
props.query.queryHashis already available in this component since each query entry in the DevTools list carries itsqueryHash.Closes #6958
Test plan
queryCache().find()calls that usequeryKeymatchingqueryKeyHashFnand async persistence (IndexedDB) recommendedSummary by CodeRabbit