Skip to content

Commit

Permalink
fix(structure): keep retrying document lists after document online
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Mar 4, 2024
1 parent ed87e2a commit 195be2e
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useCallback, useEffect, useMemo, useState} from 'react'
import {concat, fromEvent, merge, of, Subject, throwError} from 'rxjs'
import {concat, fromEvent, merge, of, retry, Subject, throwError} from 'rxjs'
import {catchError, map, mergeMap, scan, startWith, take} from 'rxjs/operators'
import {DEFAULT_STUDIO_CLIENT_OPTIONS, useClient, useSchema} from 'sanity'
import {useSearchMaxFieldDepth} from 'sanity/_internalBrowser'
Expand Down Expand Up @@ -170,9 +170,21 @@ export function useDocumentList(opts: UseDocumentListOpts): DocumentListState {
catchError((err, caught$) => {
return concat(
of({result: null, error: err}),
merge(fromEvent(window, 'online'), onRetry$).pipe(
take(1),
mergeMap(() => caught$),
merge(
fromEvent(window, 'online').pipe(
mergeMap(() =>
caught$.pipe(
retry({
delay: (_: unknown, attempt) => of(Math.max(30000, attempt * 1000)),
count: 3,
}),
),
),
),
onRetry$.pipe(
take(1),
mergeMap(() => caught$),
),
),
)
}),
Expand Down

0 comments on commit 195be2e

Please sign in to comment.