Skip to content

Commit a647f64

Browse files
committed
feat(useQuery): offline queries
guard against illegal state transitions: paused queries can unmount or get cancelled, in which case we shouldn't continue them, even if we dispatch the continue event
1 parent 2f97632 commit a647f64

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/core/query.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -538,15 +538,19 @@ export class Query<
538538
fetchFailureCount: state.fetchFailureCount + 1,
539539
}
540540
case 'pause':
541-
return {
542-
...state,
543-
fetchStatus: 'paused',
544-
}
541+
return state.fetchStatus === 'fetching'
542+
? {
543+
...state,
544+
fetchStatus: 'paused',
545+
}
546+
: state
545547
case 'continue':
546-
return {
547-
...state,
548-
fetchStatus: 'fetching',
549-
}
548+
return state.fetchStatus === 'paused'
549+
? {
550+
...state,
551+
fetchStatus: 'fetching',
552+
}
553+
: state
550554
case 'fetch':
551555
return {
552556
...state,

0 commit comments

Comments
 (0)