@@ -155,6 +155,9 @@ let fixture = (options: {
155
155
156
156
"app/routes/_index.tsx" : js `
157
157
import { useLoaderData } from "@remix-run/react";
158
+ export function shouldRevalidate(args) {
159
+ return args.defaultShouldRevalidate;
160
+ }
158
161
export default function Index() {
159
162
const t = useLoaderData();
160
163
return (
@@ -219,6 +222,13 @@ test("HMR", async ({ page }) => {
219
222
// uncomment for debugging
220
223
// page.on("console", (msg) => console.log(msg.text()));
221
224
page . on ( "pageerror" , ( err ) => console . log ( err . message ) ) ;
225
+ let dataRequests = 0 ;
226
+ page . on ( "request" , ( request ) => {
227
+ let url = new URL ( request . url ( ) ) ;
228
+ if ( url . searchParams . has ( "_data" ) ) {
229
+ dataRequests ++ ;
230
+ }
231
+ } ) ;
222
232
223
233
let portRange = makeRange ( 3080 , 3099 ) ;
224
234
let appServerPort = await getPort ( { port : portRange } ) ;
@@ -276,6 +286,9 @@ test("HMR", async ({ page }) => {
276
286
let newIndex = `
277
287
import { useLoaderData } from "@remix-run/react";
278
288
import styles from "~/styles.module.css";
289
+ export function shouldRevalidate(args) {
290
+ return args.defaultShouldRevalidate;
291
+ }
279
292
export default function Index() {
280
293
const t = useLoaderData();
281
294
return (
@@ -289,6 +302,7 @@ test("HMR", async ({ page }) => {
289
302
290
303
// detect HMR'd content and style changes
291
304
await page . waitForLoadState ( "networkidle" ) ;
305
+
292
306
let h1 = page . getByText ( "Changed" ) ;
293
307
await h1 . waitFor ( { timeout : HMR_TIMEOUT_MS } ) ;
294
308
expect ( h1 ) . toHaveCSS ( "color" , "rgb(255, 255, 255)" ) ;
@@ -305,13 +319,19 @@ test("HMR", async ({ page }) => {
305
319
expect ( await page . getByLabel ( "Root Input" ) . inputValue ( ) ) . toBe ( "asdfasdf" ) ;
306
320
await page . waitForSelector ( `#root-counter:has-text("inc 1")` ) ;
307
321
322
+ // We should not have done any revalidation yet as only UI has changed
323
+ expect ( dataRequests ) . toBe ( 0 ) ;
324
+
308
325
// add loader
309
326
let withLoader1 = `
310
327
import { json } from "@remix-run/node";
311
328
import { useLoaderData } from "@remix-run/react";
312
329
313
- export let loader = () => json({ hello: "world" })
330
+ export let loader = () => json({ hello: "world" });
314
331
332
+ export function shouldRevalidate(args) {
333
+ return args.defaultShouldRevalidate;
334
+ }
315
335
export default function Index() {
316
336
let { hello } = useLoaderData<typeof loader>();
317
337
return (
@@ -322,10 +342,14 @@ test("HMR", async ({ page }) => {
322
342
}
323
343
` ;
324
344
fs . writeFileSync ( indexPath , withLoader1 ) ;
345
+ await page . waitForLoadState ( "networkidle" ) ;
346
+
325
347
await page . getByText ( "Hello, world" ) . waitFor ( { timeout : HMR_TIMEOUT_MS } ) ;
326
348
expect ( await page . getByLabel ( "Root Input" ) . inputValue ( ) ) . toBe ( "asdfasdf" ) ;
327
349
await page . waitForSelector ( `#root-counter:has-text("inc 1")` ) ;
328
350
351
+ expect ( dataRequests ) . toBe ( 1 ) ;
352
+
329
353
let withLoader2 = `
330
354
import { json } from "@remix-run/node";
331
355
import { useLoaderData } from "@remix-run/react";
@@ -334,6 +358,9 @@ test("HMR", async ({ page }) => {
334
358
return json({ hello: "planet" })
335
359
}
336
360
361
+ export function shouldRevalidate(args) {
362
+ return args.defaultShouldRevalidate;
363
+ }
337
364
export default function Index() {
338
365
let { hello } = useLoaderData<typeof loader>();
339
366
return (
@@ -344,10 +371,14 @@ test("HMR", async ({ page }) => {
344
371
}
345
372
` ;
346
373
fs . writeFileSync ( indexPath , withLoader2 ) ;
374
+ await page . waitForLoadState ( "networkidle" ) ;
375
+
347
376
await page . getByText ( "Hello, planet" ) . waitFor ( { timeout : HMR_TIMEOUT_MS } ) ;
348
377
expect ( await page . getByLabel ( "Root Input" ) . inputValue ( ) ) . toBe ( "asdfasdf" ) ;
349
378
await page . waitForSelector ( `#root-counter:has-text("inc 1")` ) ;
350
379
380
+ expect ( dataRequests ) . toBe ( 2 ) ;
381
+
351
382
// change shared component
352
383
let updatedCounter = `
353
384
import * as React from "react";
@@ -388,6 +419,10 @@ test("HMR", async ({ page }) => {
388
419
aboutCounter = await page . waitForSelector (
389
420
`#about-counter:has-text("inc 0")`
390
421
) ;
422
+
423
+ // This should not have triggered any revalidation but our detection is
424
+ // failing for x-module changes for route module imports
425
+ // expect(dataRequests).toBe(2);
391
426
} catch ( e ) {
392
427
console . log ( "stdout begin -----------------------" ) ;
393
428
console . log ( devStdout ( ) ) ;
0 commit comments