Replies: 2 comments
-
I posted a proposed solution to this problem in the remix repo. Linking here: https://github.com/remix-run/remix/discussions/10398 |
Beta Was this translation helpful? Give feedback.
-
Pre single-fetch default behavior was:
So if it's your root loader that's expensive, you can probably just return false from it, this is actually pretty common: export function shouldRevalidate() {
return false;
} If you've got any actions that change data in the root loader, then you can include them. This one only revalidates if there's a specific formAction: export function shouldRevalidate({ formAction }) {
return formAction ? ['/some', '/action', '/urls'].includes(formAction) : false;
} This one revalidates after any action, but not any navigations. export function shouldRevalidate({ formAction }) {
return formAction && formMethod !== "GET";
} Here's the full shouldRevalidate signature: https://api.reactrouter.com/v7/interfaces/react_router.ShouldRevalidateFunctionArgs.html |
Beta Was this translation helpful? Give feedback.
-
Hey 👋
I've migrated from Remix to React Router v7, and read that the default behaviour has changed where loaders will now always re-run by default.
Developers should now make use of the
shouldRevalidate
function to ensure those don't re-run in cases where this is not wanted. What I couldn't find in the documentation, is what the default behaviour was pre-single fetch. I have a root loader which is quite intense in terms of loading time and having to figure out the default behaviour has been quite hard as I'm running into scenario's where the root loader is revalidating where I don't want it too and the same for requests that shouldn't revalidate and is doing so.Is there a code snippet somewhere that helps developers use the pre single fetch behaviour for revalidations?
Beta Was this translation helpful? Give feedback.
All reactions