@@ -17,7 +17,8 @@ describe('useSWR - focus', () => {
17
17
const key = createKey ( )
18
18
function Page ( ) {
19
19
const { data } = useSWR ( key , ( ) => value ++ , {
20
- dedupingInterval : 0
20
+ dedupingInterval : 0 ,
21
+ focusThrottleInterval : 0
21
22
} )
22
23
return < div > data: { data } </ div >
23
24
}
@@ -131,19 +132,17 @@ describe('useSWR - focus', () => {
131
132
await screen . findByText ( 'data: 0' )
132
133
133
134
await waitForNextTick ( )
134
- // trigger revalidation
135
- await focusWindow ( )
136
135
// still in throttling interval
137
136
await act ( ( ) => sleep ( 20 ) )
138
137
// should be throttled
139
138
await focusWindow ( )
140
- await screen . findByText ( 'data: 1 ' )
139
+ await screen . findByText ( 'data: 0 ' )
141
140
// wait for focusThrottleInterval
142
141
await act ( ( ) => sleep ( 100 ) )
143
142
144
143
// trigger revalidation again
145
144
await focusWindow ( )
146
- await screen . findByText ( 'data: 2 ' )
145
+ await screen . findByText ( 'data: 1 ' )
147
146
} )
148
147
149
148
it ( 'focusThrottleInterval should be stateful' , async ( ) => {
@@ -168,17 +167,17 @@ describe('useSWR - focus', () => {
168
167
await screen . findByText ( 'data: 0' )
169
168
170
169
await waitForNextTick ( )
171
- // trigger revalidation
170
+ // trigger revalidation, won't revalidate as within 50ms
172
171
await focusWindow ( )
173
172
// wait for throttle interval
174
173
await act ( ( ) => sleep ( 100 ) )
175
- // trigger revalidation
174
+ // trigger revalidation, will revalidate as 50ms passed
176
175
await focusWindow ( )
177
- await screen . findByText ( 'data: 2 ' )
176
+ await screen . findByText ( 'data: 1 ' )
178
177
179
178
await waitForNextTick ( )
180
179
// increase focusThrottleInterval
181
- fireEvent . click ( screen . getByText ( 'data: 2 ' ) )
180
+ fireEvent . click ( screen . getByText ( 'data: 1 ' ) )
182
181
// wait for throttle interval
183
182
await act ( ( ) => sleep ( 100 ) )
184
183
// trigger revalidation
@@ -187,15 +186,15 @@ describe('useSWR - focus', () => {
187
186
await act ( ( ) => sleep ( 100 ) )
188
187
// should be throttled
189
188
await focusWindow ( )
190
- await screen . findByText ( 'data: 3 ' )
189
+ await screen . findByText ( 'data: 2 ' )
191
190
192
191
// wait for throttle interval
193
192
await act ( ( ) => sleep ( 150 ) )
194
193
// trigger revalidation
195
194
await focusWindow ( )
196
195
// wait for throttle intervals
197
196
await act ( ( ) => sleep ( 150 ) )
198
- await screen . findByText ( 'data: 4 ' )
197
+ await screen . findByText ( 'data: 3 ' )
199
198
} )
200
199
201
200
it ( 'should revalidate on focus even with custom cache' , async ( ) => {
@@ -205,7 +204,8 @@ describe('useSWR - focus', () => {
205
204
function Page ( ) {
206
205
const { data } = useSWR ( key , ( ) => value ++ , {
207
206
revalidateOnFocus : true ,
208
- dedupingInterval : 0
207
+ dedupingInterval : 0 ,
208
+ focusThrottleInterval : 0
209
209
} )
210
210
return < div > data: { data } </ div >
211
211
}
0 commit comments