@@ -137,9 +137,11 @@ describe('app dir - prefetching (custom staleTime)', () => {
137
137
let requests : string [ ] = [ ]
138
138
139
139
browser . on ( 'request' , ( req ) => {
140
- // only consider requests that have RSC header but not the prefetch header
141
- if ( req . headers ( ) [ 'rsc' ] && ! req . headers ( ) [ 'next-router-prefetch' ] ) {
142
- requests . push ( new URL ( req . url ( ) ) . pathname )
140
+ const path = new URL ( req . url ( ) ) . pathname
141
+ const headers = req . headers ( )
142
+
143
+ if ( headers [ 'rsc' ] ) {
144
+ requests . push ( path )
143
145
}
144
146
} )
145
147
@@ -164,4 +166,73 @@ describe('app dir - prefetching (custom staleTime)', () => {
164
166
) . toHaveLength ( 1 )
165
167
} )
166
168
} )
169
+
170
+ it ( 'should renew the stale time after refetching expired RSC data' , async ( ) => {
171
+ const browser = await next . browser ( '/404' )
172
+ let requests : string [ ] = [ ]
173
+
174
+ browser . on ( 'request' , ( req ) => {
175
+ requests . push ( new URL ( req . url ( ) ) . pathname )
176
+ } )
177
+
178
+ // Navigate to home and wait for static page to be prefetched
179
+ await browser . eval ( 'location.href = "/"' )
180
+
181
+ await retry ( async ( ) => {
182
+ expect (
183
+ requests . filter ( ( request ) => request === '/static-page' )
184
+ ) . toHaveLength ( 1 )
185
+ } )
186
+
187
+ // Navigate to static page (should use cached data)
188
+ await browser
189
+ . elementByCss ( '#to-static-page' )
190
+ . click ( )
191
+ . waitForElementByCss ( '#static-page' )
192
+
193
+ // Go back to home
194
+ await browser
195
+ . elementByCss ( '#to-home' )
196
+ . click ( )
197
+ . waitForElementByCss ( '#to-static-page' )
198
+
199
+ // Wait for stale time to expire (10 seconds)
200
+ await waitFor ( 10000 )
201
+
202
+ // Navigate to static page again (should refetch due to expired cache)
203
+ await browser
204
+ . elementByCss ( '#to-static-page' )
205
+ . click ( )
206
+ . waitForElementByCss ( '#static-page' )
207
+
208
+ // Verify that refetch happened
209
+ await retry ( async ( ) => {
210
+ expect (
211
+ requests . filter ( ( request ) => request === '/static-page' )
212
+ ) . toHaveLength ( 2 )
213
+ } )
214
+
215
+ // Go back to home
216
+ await browser
217
+ . elementByCss ( '#to-home' )
218
+ . click ( )
219
+ . waitForElementByCss ( '#to-static-page' )
220
+
221
+ // Wait less than the stale time (5 seconds - should still be fresh)
222
+ await waitFor ( 5000 )
223
+
224
+ // Navigate to static page again (should NOT refetch - stale time should be renewed)
225
+ await browser
226
+ . elementByCss ( '#to-static-page' )
227
+ . click ( )
228
+ . waitForElementByCss ( '#static-page' )
229
+
230
+ // This should still be 2 - no new request should have been made
231
+ // If this fails, it means the stale time was not renewed after the refetch
232
+ await retry ( async ( ) => {
233
+ expect (
234
+ requests . filter ( ( request ) => request === '/static-page' )
235
+ ) . toHaveLength ( 2 )
236
+ } )
237
+ } )
167
238
} )
0 commit comments