Skip to content

Conversation

@FEgor04
Copy link

@FEgor04 FEgor04 commented Dec 11, 2025

I faced a bug when switching events that share property name.

Example: we have two events test-first and test-second, both with properties property, as on the screenshots below:
image
image

Then, if we switch between them, it will not update the UI and we will have a situation like below: test-second with properties from previous event:
image

Turns out, the problem is that filters contain an event: undefined entry that resets event to undefined and causes it to misuse the cache. This PR fixes it by moving event and propertyName to the end of dict, as in get function below.

@vercel
Copy link

vercel bot commented Dec 11, 2025

@FEgor04 is attempting to deploy a commit to the umami-software Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 11, 2025

Greptile Overview

Greptile Summary

This PR fixes a React Query cache invalidation bug that occurred when switching between events with shared property names. The issue was caused by the filters object containing an event: undefined property that would overwrite the specific event parameter in the query key. When users switched between events like test-first and test-second that both had properties named property, the UI would display stale data from the previous event. The fix reorders the queryKey object construction to place event and propertyName after the spread operation, ensuring these specific parameters override any conflicting values from filters. This change integrates with the existing query caching system by ensuring unique cache keys are generated for each event-property combination, preventing incorrect data display.

Important Files Changed

Filename Score Overview
src/components/hooks/queries/useEventDataValuesQuery.ts 5/5 Fixed cache invalidation by reordering queryKey parameters to prevent event: undefined from overriding specific event values

Confidence score: 5/5

  • This PR is safe to merge with minimal risk as it addresses a specific cache invalidation bug with a targeted fix
  • Score reflects a simple parameter reordering that fixes a well-documented issue without introducing complexity or breaking changes
  • No files require special attention as the change is isolated and straightforward

Sequence Diagram

sequenceDiagram
    participant User
    participant Component
    participant useEventDataValuesQuery
    participant useApi
    participant useDateParameters
    participant useFilterParameters
    participant ReactQuery
    participant API

    User->>Component: "Switch between events with same property"
    Component->>useEventDataValuesQuery: "Call hook with websiteId, event, propertyName"
    useEventDataValuesQuery->>useApi: "Get API functions"
    useApi-->>useEventDataValuesQuery: "Return { get, useQuery }"
    useEventDataValuesQuery->>useDateParameters: "Get date parameters"
    useDateParameters-->>useEventDataValuesQuery: "Return { startAt, endAt, unit, timezone }"
    useEventDataValuesQuery->>useFilterParameters: "Get filter parameters"
    useFilterParameters-->>useEventDataValuesQuery: "Return filters object"
    useEventDataValuesQuery->>ReactQuery: "Call useQuery with queryKey and queryFn"
    Note over ReactQuery: "Cache key includes event and propertyName at end"
    ReactQuery->>API: "Execute queryFn: GET /websites/{websiteId}/event-data/values"
    API-->>ReactQuery: "Return event data values"
    ReactQuery-->>useEventDataValuesQuery: "Return query result"
    useEventDataValuesQuery-->>Component: "Return query data"
    Component-->>User: "Display updated event values"
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant