Skip to content

Commit 195a1d4

Browse files
jacob-ebeymcansh
authored andcommitted
fix: better opt out of loader revalidation on UI only changes
1 parent b8a2ecf commit 195a1d4

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/react": patch
3+
---
4+
5+
better opt out of loader revalidation on UI only changes

integration/hmr-log-test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ let fixture = (options: {
156156
"app/routes/_index.tsx": js`
157157
import { useLoaderData } from "@remix-run/react";
158158
export function shouldRevalidate(args) {
159-
return args.defaultShouldRevalidate;
159+
return true;
160160
}
161161
export default function Index() {
162162
const t = useLoaderData();
@@ -286,7 +286,7 @@ test("HMR", async ({ page }) => {
286286
import { useLoaderData } from "@remix-run/react";
287287
import styles from "~/styles.module.css";
288288
export function shouldRevalidate(args) {
289-
return args.defaultShouldRevalidate;
289+
return true;
290290
}
291291
export default function Index() {
292292
const t = useLoaderData();
@@ -329,7 +329,7 @@ test("HMR", async ({ page }) => {
329329
export let loader = () => json({ hello: "world" });
330330
331331
export function shouldRevalidate(args) {
332-
return args.defaultShouldRevalidate;
332+
return true;
333333
}
334334
export default function Index() {
335335
let { hello } = useLoaderData<typeof loader>();
@@ -358,7 +358,7 @@ test("HMR", async ({ page }) => {
358358
}
359359
360360
export function shouldRevalidate(args) {
361-
return args.defaultShouldRevalidate;
361+
return true;
362362
}
363363
export default function Index() {
364364
let { hello } = useLoaderData<typeof loader>();

integration/hmr-test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ let fixture = (options: {
156156
"app/routes/_index.tsx": js`
157157
import { useLoaderData } from "@remix-run/react";
158158
export function shouldRevalidate(args) {
159-
return args.defaultShouldRevalidate;
159+
return true;
160160
}
161161
export default function Index() {
162162
const t = useLoaderData();
@@ -286,7 +286,7 @@ test("HMR", async ({ page }) => {
286286
import { useLoaderData } from "@remix-run/react";
287287
import styles from "~/styles.module.css";
288288
export function shouldRevalidate(args) {
289-
return args.defaultShouldRevalidate;
289+
return true;
290290
}
291291
export default function Index() {
292292
const t = useLoaderData();
@@ -329,7 +329,7 @@ test("HMR", async ({ page }) => {
329329
export let loader = () => json({ hello: "world" });
330330
331331
export function shouldRevalidate(args) {
332-
return args.defaultShouldRevalidate;
332+
return true;
333333
}
334334
export default function Index() {
335335
let { hello } = useLoaderData<typeof loader>();
@@ -358,7 +358,7 @@ test("HMR", async ({ page }) => {
358358
}
359359
360360
export function shouldRevalidate(args) {
361-
return args.defaultShouldRevalidate;
361+
return true;
362362
}
363363
export default function Index() {
364364
let { hello } = useLoaderData<typeof loader>();

packages/remix-react/routes.tsx

+7-11
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,18 @@ function createShouldRevalidate(
180180
let module = routeModules[route.id];
181181
invariant(module, `Expected route module to be loaded for ${route.id}`);
182182

183-
if (module.shouldRevalidate) {
184-
if (typeof needsRevalidation === "boolean" && !handledRevalidation) {
185-
handledRevalidation = true;
186-
return module.shouldRevalidate({
187-
...arg,
188-
defaultShouldRevalidate: needsRevalidation,
189-
});
190-
}
191-
return module.shouldRevalidate(arg);
192-
}
193-
183+
// When an HMR / HDR update happens we opt out of all user-defined
184+
// revalidation logic and the do as the dev server tells us the first
185+
// time router.revalidate() is called.
194186
if (typeof needsRevalidation === "boolean" && !handledRevalidation) {
195187
handledRevalidation = true;
196188
return needsRevalidation;
197189
}
198190

191+
if (module.shouldRevalidate) {
192+
return module.shouldRevalidate(arg);
193+
}
194+
199195
return arg.defaultShouldRevalidate;
200196
};
201197
}

0 commit comments

Comments
 (0)