Skip to content

Commit 7a32737

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(kb): expire pending connector state
1 parent 78804c9 commit 7a32737

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

apps/sim/hooks/queries/kb/connectors.test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
77
const mocks = vi.hoisted(() => ({
88
requestJson: vi.fn(),
99
useInfiniteQuery: vi.fn(),
10+
useQuery: vi.fn(),
1011
}))
1112

1213
vi.mock('@tanstack/react-query', () => ({
1314
keepPreviousData: Symbol('keepPreviousData'),
1415
useInfiniteQuery: mocks.useInfiniteQuery,
1516
useMutation: vi.fn(),
16-
useQuery: vi.fn(),
17+
useQuery: mocks.useQuery,
1718
useQueryClient: vi.fn(() => ({ invalidateQueries: vi.fn() })),
1819
}))
1920

@@ -26,7 +27,11 @@ import {
2627
listKnowledgeConnectorDocumentsContract,
2728
} from '@/lib/api/contracts/knowledge'
2829
import { MAX_KNOWLEDGE_CONNECTOR_DOCUMENT_PAGE_SIZE } from '@/lib/knowledge/constants'
29-
import { isConnectorSyncingOrPending, useConnectorDocuments } from '@/hooks/queries/kb/connectors'
30+
import {
31+
isConnectorSyncingOrPending,
32+
useConnectorDocuments,
33+
useConnectorList,
34+
} from '@/hooks/queries/kb/connectors'
3035

3136
const NOW_MS = new Date('2026-08-21T12:00:00.000Z').getTime()
3237

@@ -67,6 +72,10 @@ interface ConnectorDocumentsQueryOptions {
6772
) => number | undefined
6873
}
6974

75+
interface ConnectorListQueryOptions {
76+
notifyOnChangeProps?: 'all'
77+
}
78+
7079
describe('isConnectorSyncingOrPending', () => {
7180
beforeEach(() => {
7281
vi.spyOn(Date, 'now').mockReturnValue(NOW_MS)
@@ -114,6 +123,19 @@ describe('isConnectorSyncingOrPending', () => {
114123
)
115124
})
116125

126+
describe('useConnectorList', () => {
127+
beforeEach(() => {
128+
vi.clearAllMocks()
129+
})
130+
131+
it('notifies consumers when identical polls complete so pending UI can expire', () => {
132+
useConnectorList('knowledge-1')
133+
134+
const options = mocks.useQuery.mock.calls[0]?.[0] as ConnectorListQueryOptions
135+
expect(options.notifyOnChangeProps).toBe('all')
136+
})
137+
})
138+
117139
describe('useConnectorDocuments', () => {
118140
beforeEach(() => {
119141
vi.clearAllMocks()

apps/sim/hooks/queries/kb/connectors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ export function useConnectorList(knowledgeBaseId?: string) {
8686
enabled: Boolean(knowledgeBaseId),
8787
staleTime: CONNECTOR_LIST_STALE_TIME,
8888
placeholderData: keepPreviousData,
89+
// Pending state is time-based, so identical poll responses must still trigger a render
90+
// for consumers to drop the pending UI when its two-minute window expires.
91+
notifyOnChangeProps: 'all',
8992
refetchInterval: (query) => {
9093
const connectors = query.state.data
9194
if (!connectors?.length) return false

0 commit comments

Comments
 (0)