@@ -38,6 +38,13 @@ export function useSubscription<TData = any, TVariables = OperationVariables>(
38
38
} ) ;
39
39
} ) ;
40
40
41
+ const canResetObservableRef = useRef ( false ) ;
42
+ useEffect ( ( ) => {
43
+ return ( ) => {
44
+ canResetObservableRef . current = true ;
45
+ } ;
46
+ } , [ ] ) ;
47
+
41
48
const ref = useRef ( { client, subscription, options } ) ;
42
49
useEffect ( ( ) => {
43
50
let shouldResubscribe = options ?. shouldResubscribe ;
@@ -46,23 +53,24 @@ export function useSubscription<TData = any, TVariables = OperationVariables>(
46
53
}
47
54
48
55
if ( options ?. skip ) {
49
- if ( ! options ?. skip !== ! ref . current . options ?. skip ) {
56
+ if ( ! options ?. skip !== ! ref . current . options ?. skip || canResetObservableRef . current ) {
50
57
setResult ( {
51
58
loading : false ,
52
59
data : void 0 ,
53
60
error : void 0 ,
54
61
variables : options ?. variables ,
55
62
} ) ;
56
63
setObservable ( null ) ;
64
+ canResetObservableRef . current = false ;
57
65
}
58
66
} else if (
59
- shouldResubscribe !== false && (
60
- client !== ref . current . client ||
61
- subscription !== ref . current . subscription ||
62
- options ?. fetchPolicy !== ref . current . options ?. fetchPolicy ||
63
- ! options ?. skip !== ! ref . current . options ?. skip ||
64
- ! equal ( options ?. variables , ref . current . options ?. variables )
65
- )
67
+ ( shouldResubscribe !== false &&
68
+ ( client !== ref . current . client ||
69
+ subscription !== ref . current . subscription ||
70
+ options ?. fetchPolicy !== ref . current . options ?. fetchPolicy ||
71
+ ! options ?. skip !== ! ref . current . options ?. skip ||
72
+ ! equal ( options ?. variables , ref . current . options ?. variables ) ) ) ||
73
+ canResetObservableRef . current
66
74
) {
67
75
setResult ( {
68
76
loading : true ,
@@ -76,10 +84,11 @@ export function useSubscription<TData = any, TVariables = OperationVariables>(
76
84
fetchPolicy : options ?. fetchPolicy ,
77
85
context : options ?. context ,
78
86
} ) ) ;
87
+ canResetObservableRef . current = false ;
79
88
}
80
89
81
90
Object . assign ( ref . current , { client, subscription, options } ) ;
82
- } , [ client , subscription , options ] ) ;
91
+ } , [ client , subscription , options , canResetObservableRef . current ] ) ;
83
92
84
93
useEffect ( ( ) => {
85
94
if ( ! observable ) {
0 commit comments