Skip to content

Commit c8b52c9

Browse files
committed
Slight clenaup
1 parent 643cde0 commit c8b52c9

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

packages/react-router/lib/dom/ssr/routes.tsx

+5-16
Original file line numberDiff line numberDiff line change
@@ -585,30 +585,19 @@ function getShouldRevalidateFunction(
585585
// If users are somehow re-generating updated versions of these on the backend
586586
// they can still opt-into revalidation which will make the `.data` request
587587
if (!ssr && manifestRoute.hasLoader && !manifestRoute.hasClientLoader) {
588-
let [, params] = path ? compilePath(path) : [null, []];
589-
let paramNames = params.map((p) => p.paramName);
590-
const getDefaultShouldRevalidate = ({
591-
currentParams,
592-
nextParams,
593-
}: ShouldRevalidateFunctionArgs) => {
594-
for (let param of paramNames) {
595-
if (currentParams[param] !== nextParams[param]) {
596-
return true;
597-
}
598-
}
599-
return false;
600-
};
588+
let myParams = path ? compilePath(path)[1].map((p) => p.paramName) : [];
589+
const didParamsChange = (opts: ShouldRevalidateFunctionArgs) =>
590+
myParams.some((p) => opts.currentParams[p] !== opts.nextParams[p]);
601591

602592
if (route.shouldRevalidate) {
603593
let fn = route.shouldRevalidate;
604594
return (opts: ShouldRevalidateFunctionArgs) =>
605595
fn({
606596
...opts,
607-
defaultShouldRevalidate: getDefaultShouldRevalidate(opts),
597+
defaultShouldRevalidate: didParamsChange(opts),
608598
});
609599
} else {
610-
return (opts: ShouldRevalidateFunctionArgs) =>
611-
getDefaultShouldRevalidate(opts);
600+
return (opts: ShouldRevalidateFunctionArgs) => didParamsChange(opts);
612601
}
613602
}
614603

0 commit comments

Comments
 (0)