feat(projects): Load project stats with react query, remove ProjectsStatsStore#115463
Open
scttcper wants to merge 5 commits into
Open
feat(projects): Load project stats with react query, remove ProjectsStatsStore#115463scttcper wants to merge 5 commits into
scttcper wants to merge 5 commits into
Conversation
Project cards were still going through the old Reflux stats store and mutating project-shaped data with endpoint-expanded stats fields. Move the dashboard over to useAggregatedQueryKeys, keep stats separate from the base Project type, and let the project card read stats through the new hook. Co-Authored-By: Codex <noreply@openai.com>
Contributor
📊 Type Coverage Diff✅ No new type safety issues introduced. Coverage: 93.51% |
Project cards could flash back to loading after being unmounted for a bit because the aggregate hook only reduced cached responses for the local ids it had already buffered. Allow callers to synchronously read cached aggregate data for a specific id before queueing another request, so scrolling back to a project card keeps the stats around. Co-Authored-By: Codex <noreply@openai.com>
scttcper
commented
May 13, 2026
| }; | ||
|
|
||
| export function ProjectStatsGraph({project, stats}: Props) { | ||
| stats = stats || project.stats || []; |
The customer details test hits the projects endpoint with statsPeriod=30d, but the shared getsentry project fixture no longer carries stats by default. Keep stats out of the base fixture and add the endpoint-expanded field at the mock response instead. Co-Authored-By: Codex <noreply@openai.com>
Comment on lines
+108
to
116
| (aggregates = prevQueryKeys.current) => | ||
| queryClient | ||
| .getQueriesData<ApiResponse<Data>>({ | ||
| .getQueriesData<ApiResponse<ResponseData>>({ | ||
| predicate: ({queryKey}) => isApiQueryKeyForUrl(queryKey), | ||
| }) | ||
| .flatMap(([, val]) => (defined(val) ? [val] : [])) | ||
| .reduce<Data | undefined>( | ||
| (prevValue, val) => responseReducer(prevValue, val, prevQueryKeys.current), | ||
| (prevValue, val) => responseReducer(prevValue, val, aggregates), | ||
| undefined |
Contributor
There was a problem hiding this comment.
Bug: The readCache function incorrectly matches cached queries by URL only, ignoring query parameters. This leads to data from unrelated API calls being mixed, causing data loss.
Severity: HIGH
Suggested Fix
Update the readCache predicate to filter queries using the full query key, including query parameters, not just the URL path. This will ensure that only responses with the exact same parameters and expected data structure are processed, preventing cross-contamination from unrelated API calls.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: static/app/utils/api/useAggregatedQueryKeys.tsx#L108-L116
Potential issue: The `readCache` function in `useAggregatedQueryKeys` filters cached
React Query data by URL path only, ignoring query parameters. This causes it to retrieve
data from different API calls to the same endpoint that have different response
structures. For example, it can mix a response from the `OrganizationProjects` page
(which uses `collapse` to remove stats) with a response for the dashboard (which
includes stats). The `responseReducer` in `useProjectStats` can then process the
stat-less response, causing previously cached project statistics to be lost and leading
to missing data on the dashboard.
Also affects:
static/app/views/settings/organizationProjects/index.tsx:52~63static/app/views/projectsDashboard/useProjectStats.tsx:62~74
Did we get this right? 👍 / 👎 to inform future reviews.
# Conflicts: # static/app/types/project.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Kills the ProjectsStatsStore. Mostly used on the /projects/ page. Allows us to remove some types from the global project object that typically don't exist via the ProjectsStore.