-
Notifications
You must be signed in to change notification settings - Fork 1
fix(core): add perspective to query cache key to avoid collisions #609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): add perspective to query cache key to avoid collisions #609
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| [selectedDocument, selectedPerspective], | ||
| ) | ||
|
|
||
| const documentProjectionOptions = useMemo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related, but the old implementation caused infinite loading due to recalculating the params passed to documentProjection. That might be something we want to resolve in the hook itself at a later date, but it was annoying me 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I thought kitchensink was using react 19 and compiler, maybe we removed it
ec7f9d0 to
31a82c6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a query cache collision bug that occurred when using nested ResourceProviders with different perspectives but the same project/dataset. The core issue was that query cache keys didn't include perspective information, causing incorrect cached results to be served across different perspective contexts.
Key changes:
- Added perspective normalization to query cache keys to prevent collisions
- Created comprehensive test coverage for both implicit and explicit perspective scenarios
- Added a demonstration route and e2e tests to verify the fix
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/query/queryStore.ts | Core fix: normalizes query options to include perspective in cache keys |
| packages/core/src/query/queryStore.test.ts | Unit tests for perspective-based cache separation |
| apps/kitchensink-react/src/routes/PerspectivesRoute.tsx | Demo component showing nested ResourceProviders with different perspectives |
| apps/kitchensink-react/src/AppRoutes.tsx | Route registration for the new perspectives demo |
| apps/kitchensink-react/src/routes/releases/ReleasesRoute.tsx | Refactored to use memoized projection options |
| apps/kitchensink-react/e2e/perspectives.spec.ts | E2e test verifying published panels don't show draft content |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
31a82c6 to
4833f13
Compare
4833f13 to
db59c7f
Compare
db59c7f to
4a00e50
Compare
binoy14
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense to me, thanks
| [selectedDocument, selectedPerspective], | ||
| ) | ||
|
|
||
| const documentProjectionOptions = useMemo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I thought kitchensink was using react 19 and compiler, maybe we removed it

Description
There was a subtle bug that could happen if you used a nested
ResourceProviderwith a perspective (or any other way of implicitly getting a perspective) that pointed to the same project and dataset as anotherResourceProvider, wherein you might get the wrong query result. You can see this if you run this branch and check the new route in Kitchensink without the queryStore fix, as below:Every query store is instanced to a project and dataset, and it caches the results of a query. If you were to make the exact same query in a different provider with a different perspective, your "new" perspective would not be saved in the query key, and you would be served the old cached query result with from the "wrong" perspective, because neither query saved their perspective as part of their query key.
(this wasn't a problem with something like
useDocument({...documentHandle, perspective})because all options got memoized into the key)This PR rectifies this by forcing every query key to have a perspective. It also adds tests and e2e tests. New results below:
What to review
The only significant logic change is in
queryStore.ts. Everything else is testing / future-proofing.PerspectivesRoutecomponent that demonstrates nestedResourceProvidercomponents with different perspectivesTesting
Added a comprehensive e2e test that:
Fun gif