diff --git a/src/state/queries/notifications/__tests__/unread.test.tsx b/src/state/queries/notifications/__tests__/unread.test.tsx index e7339f5fb..54a83eb56 100644 --- a/src/state/queries/notifications/__tests__/unread.test.tsx +++ b/src/state/queries/notifications/__tests__/unread.test.tsx @@ -167,52 +167,6 @@ describe('notification unread synchronization', () => { expect(mockTruncateAndInvalidate).toHaveBeenCalledTimes(2) }) - it('continues empty and sparse pages before caching the visible results', async () => { - mockFetchPage - .mockResolvedValueOnce({page: {...page, cursor: 'empty'}, indexedAt: ''}) - .mockResolvedValueOnce({ - page: {...visiblePage, cursor: 'sparse'}, - indexedAt: '2026-09-01T00:00:00.000Z', - }) - .mockResolvedValueOnce({page: visiblePage, indexedAt: ''}) - const {result} = setup() - await act(() => result.current.api.checkUnread({invalidate: true})) - expect(result.current.count).toBe('4') - for (const [index, cursor] of [undefined, 'empty', 'sparse'].entries()) { - expect(mockFetchPage).toHaveBeenNthCalledWith( - index + 1, - expect.objectContaining({cursor}), - ) - } - expect(result.current.api.getCachedUnreadPage()?.items).toHaveLength(4) - expect(result.current.api.getCachedUnreadPage()?.cursor).toBeUndefined() - }) - - it('stops following a repeated cursor', async () => { - mockFetchPage.mockResolvedValue({ - page: {...page, cursor: 'same'}, - indexedAt: '', - }) - const {result} = setup() - await act(() => result.current.api.checkUnread()) - expect(mockFetchPage).toHaveBeenCalledTimes(2) - expect(result.current.count).toBe('') - }) - - it('bounds continuation through empty pages with unique cursors', async () => { - let cursor = 0 - mockFetchPage.mockImplementation(() => - Promise.resolve({ - page: {...page, cursor: String(cursor++)}, - indexedAt: '', - }), - ) - const {result} = setup() - await act(() => result.current.api.checkUnread()) - expect(mockFetchPage).toHaveBeenCalledTimes(4) - expect(result.current.count).toBe('') - }) - it('preserves the prior badge and cache when the page request fails', async () => { mockFetchPage.mockResolvedValueOnce({page: visiblePage, indexedAt: ''}) const {result} = setup() diff --git a/src/state/queries/notifications/unread.tsx b/src/state/queries/notifications/unread.tsx index 9a089ad17..ad5b28a60 100644 --- a/src/state/queries/notifications/unread.tsx +++ b/src/state/queries/notifications/unread.tsx @@ -24,8 +24,6 @@ import {RQKEY as RQKEY_NOTIFS} from './feed' import {type CachedFeedPage, type FeedPage} from './types' import {fetchPage} from './util' -const MAX_UNREAD_PAGE_CONTINUATIONS = 3 - const UPDATE_INTERVAL = 30 * 1e3 // 30sec const broadcast = new BroadcastChannel('NOTIFS_BROADCAST_CHANNEL') @@ -170,7 +168,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { isFetchingRef.current = true const generation = ++refreshGenerationRef.current - let {page, indexedAt: lastIndexed} = await fetchPage({ + const {page, indexedAt: lastIndexed} = await fetchPage({ agent, cursor: undefined, limit: 40, @@ -180,36 +178,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) { reasons: [], fetchAdditionalData: !!invalidate, }) - const visitedCursors = new Set() - let attemptCount = 0 - while ( - countUnread(page) < 30 && - page.cursor && - page.items.length < 40 && - attemptCount < MAX_UNREAD_PAGE_CONTINUATIONS - ) { - if (generation !== refreshGenerationRef.current) return - const cursor = page.cursor - if (visitedCursors.has(cursor)) break - visitedCursors.add(cursor) - const next = await fetchPage({ - agent, - cursor, - limit: 40, - queryClient, - moderationOpts, - hideFollowNotifications: undefined, - reasons: [], - fetchAdditionalData: !!invalidate, - }) - lastIndexed ||= next.indexedAt - page = { - ...page, - items: [...page.items, ...next.page.items], - cursor: next.page.cursor, - } - attemptCount++ - } const now = new Date() const lastIndexedDate = lastIndexed ? new Date(lastIndexed)