Skip to content

Commit 5865b44

Browse files
committed
fix(knowledge): keep watching member enrollment until it connects
1 parent 0a769e9 commit 5865b44

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,9 @@ interface ConnectMemberAccountParams {
483483
* Connects the viewer's own account to a per-member connector. Desktop and
484484
* direct OAuth settle when the connection completes. An ordinary knowledge
485485
* base hands the viewer an invitation page in a new tab that reports nothing
486-
* back, so its refresh waits for the viewer to return to this tab.
486+
* back, so it refreshes each time the viewer returns to this tab until the
487+
* viewer's membership reads `connected`. The listener belongs to the attempt's
488+
* abort signal, so a newer attempt or unmount removes it.
487489
*/
488490
export function useStartConnectorMemberEnrollment() {
489491
const queryClient = useQueryClient()
@@ -545,12 +547,15 @@ export function useStartConnectorMemberEnrollment() {
545547
tab?.close()
546548
throw error
547549
}
548-
const refreshOnReturn = () => {
550+
const refreshUntilConnected = async () => {
549551
if (document.visibilityState !== 'visible') return
550-
document.removeEventListener('visibilitychange', refreshOnReturn)
551-
void refresh(knowledgeBaseId)
552+
await refresh(knowledgeBaseId)
553+
const connector = getCachedConnector(queryClient, knowledgeBaseId, connectorId)
554+
if (connector?.viewerMembership === 'connected') controller.abort()
552555
}
553-
document.addEventListener('visibilitychange', refreshOnReturn)
556+
document.addEventListener('visibilitychange', () => void refreshUntilConnected(), {
557+
signal: controller.signal,
558+
})
554559
return false
555560
},
556561
onSettled: (completed, _error, { knowledgeBaseId }) =>

0 commit comments

Comments
 (0)