fix: preserve sessions date filter when closing session modal#4114
fix: preserve sessions date filter when closing session modal#4114Lokimorty wants to merge 1 commit intoumami-software:masterfrom
Conversation
|
@Lokimorty is attempting to deploy a commit to the Umami Software Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR fixes a bug where the Sessions page date filter (e.g. "Last 7 days") was silently dropped back to the default when a user closed the session detail modal. The root cause was a stale-state anti-pattern in Key changes:
The fix is minimal, correct, and well-scoped. Confidence Score: 5/5Safe to merge — the change is a well-targeted removal of a stale-state pattern with no new logic introduced. The change is small, focused, and directly addresses the documented root cause. The new approach (reading useSearchParams() directly) is idiomatic for Next.js App Router and eliminates the one-render-gap race that caused the bug. buildPath already handles undefined values correctly, so the type-signature broadening is safe. No P0 or P1 issues were found. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant C as Component
participant uN as useNavigation
participant uSP as useSearchParams()
participant bP as buildPath()
Note over uN: Before (stale-state pattern)
C->>uN: mount / render
uN->>uSP: initial read → useState(Object.fromEntries(searchParams))
Note over uN: queryParams state = snapshot at mount
C->>uN: user changes date filter (searchParams updated)
uN-->>uN: useEffect fires → setQueryParams(new snapshot)
Note over uN: 1 render gap where queryParams is stale
C->>uN: updateParams({view: 'session'})
uN->>bP: buildPath(pathname, { ...staleQueryParams, view:'session' })
Note over bP: date param may be missing
Note over uN: After (live read)
C->>uN: mount / render
uN->>uSP: Object.fromEntries(searchParams.entries()) — always current
C->>uN: updateParams({view: 'session'})
uN->>bP: buildPath(pathname, { ...liveQueryParams, view:'session' })
Note over bP: date param preserved correctly
Reviews (1): Last reviewed commit: "fix: preserve sessions date filter when ..." | Re-trigger Greptile |
Summary
When a user selects a custom Sessions page date filter such as
Last 7 days, opens a session, and then closes the session modal, the page currently falls back to the defaultLast 24 hoursfilter.Root Cause
useNavigation()was copyingsearchParamsinto local state and syncing them in an effect. That meantupdateParams()could build the modal close URL from stale query state and drop the currentdateparameter.Fix
Use the current
useSearchParams()values directly when building URLs instead of mirroring them through local state.This keeps the existing query string intact when the session modal is opened or closed, so the selected Sessions date filter persists as expected.
Changed Files
src/components/hooks/useNavigation.ts— remove the mirrored query state and buildquery,updateParams(), andrenderUrl()from the live search params