Repository navigation
fix: restore document query cache matching - #18376
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe change centralizes document query-key factories, re-exports them from the request hook, broadens cache invalidation targets, and adds prefix-matching tests for list and filter keys. ChangesDocument query cache updates
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This localized cache-key fix is merge-ready after normal checks and review; no actionable merge-blocking risk remains. Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
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 |
wangq8
left a comment
There was a problem hiding this comment.
Review
Thanks for the fix — this correctly addresses the cache-matching regression. I verified the behavior against TanStack Query v5's actual partialMatchKey semantics.
What's correct
- The root cause is real:
DocumentKeys.list()with no args produced['fetchDocumentList', undefined, undefined, undefined], which never partial-matched the parameterized list key['fetchDocumentList', searchString, pagination, filter]. Same forfilter(). - Introducing explicit prefix keys (
all()→['fetchDocumentList'],allFilters()→['fetchDocumentFilter']) is the idiomatic fix. - The tests use
partialMatchKey(actual, prefix)with the correct argument order and assert the real matching behavior. Good.
Things to consider (non-blocking)
-
partialMatchKeyis an internal API from a transitive dependency. The test imports it directly from@tanstack/query-core, which is not declared inweb/package.json(it is a transitive dep of@tanstack/react-query).partialMatchKeyis an internal utility, not part of the public API surface. This is fragile — it can break on a minor bump or under stricter resolvers (pnpm/yarn PnP). Consider either declaring@tanstack/query-coreexplicitly in devDependencies, or (better) asserting through the realQueryClient/invalidateQueriesbehavior instead of reaching into internals. -
all()now also matchesbyIds.byIdsuses['fetchDocumentList', 'byIds', ids], soinvalidateQueries({ queryKey: DocumentKeys.all() })andsetQueriesData({ queryKey: DocumentKeys.all() })now also targetbyIdsqueries (previously theundefined-suffixed key never matched them). This looks like a desirable side effect — e.g. the optimistic run-status updates inuseRunDocumentnow also keep thebyIdscache in sync — but please confirm it is intended. -
Minor consistency:
use-manage-modal.ts:388still hardcodesqueryKey: [DocumentApiAction.FetchDocumentList]instead ofDocumentKeys.all(). Optional follow-up to consolidate on the shared factory.
No regressions found in the diff itself; the re-export of DocumentApiAction keeps the existing import in use-manage-modal.ts working.
What problem does this PR solve?
Fixes document query cache matching after the query key factory refactor. Prefix operations previously generated keys with trailing
undefinedvalues, causinginvalidateQueriesand optimisticsetQueriesDataupdates to miss parameterized document list and filter queries.This PR introduces explicit prefix keys and adds regression tests using TanStack Query’s actual partial matching behavior.
Type of change