Skip to content

Commit 4eff201

Browse files
heavygeecursoragent
andcommitted
fix(web): advance session last-seen while selected session updates
Keep the unread watermark in sync with live session activity so navigating away from an open session does not show a false unread dot. Addresses review on tiann#699 Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 407130c commit 4eff201

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, expect, it, beforeEach } from 'vitest'
2+
import { getSessionLastSeenAt, markSessionSeen } from './sessionLastSeen'
3+
4+
describe('sessionLastSeen', () => {
5+
beforeEach(() => {
6+
localStorage.clear()
7+
})
8+
9+
it('stores the latest seen timestamp for a session', () => {
10+
markSessionSeen('session-a', 1000)
11+
markSessionSeen('session-a', 2500)
12+
expect(getSessionLastSeenAt('session-a')).toBe(2500)
13+
})
14+
15+
it('does not move the watermark backwards', () => {
16+
markSessionSeen('session-a', 5000)
17+
markSessionSeen('session-a', 2000)
18+
expect(getSessionLastSeenAt('session-a')).toBe(5000)
19+
})
20+
})

web/src/router.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,16 @@ function SessionsPage() {
150150
}, [machines])
151151
const sessionMatch = matchRoute({ to: '/sessions/$sessionId', fuzzy: true })
152152
const selectedSessionId = sessionMatch && sessionMatch.sessionId !== 'new' ? sessionMatch.sessionId : null
153+
const selectedSession = useMemo(
154+
() => sessions.find((session) => session.id === selectedSessionId) ?? null,
155+
[sessions, selectedSessionId]
156+
)
153157
useEffect(() => {
154-
if (selectedSessionId) {
155-
markSessionSeen(selectedSessionId)
158+
if (!selectedSessionId) {
159+
return
156160
}
157-
}, [selectedSessionId])
161+
markSessionSeen(selectedSessionId, Math.max(Date.now(), selectedSession?.updatedAt ?? 0))
162+
}, [selectedSessionId, selectedSession?.updatedAt])
158163
const isSessionsIndex = pathname === '/sessions' || pathname === '/sessions/'
159164
const sidebar = useSidebarResize()
160165
const handleNewSessionInDirectory = useCallback((args: { machineId: string | null; directory: string }) => {

0 commit comments

Comments
 (0)