Callsite Revalidation Opt-out #10006
Replies: 2 comments 1 reply
-
Are there any news on this one? I'm currently handling a sort of similar scenario where I'm using a Currently I'm thinking of just opting out entirely off the |
Beta Was this translation helpful? Give feedback.
-
This is our biggest pain point for Remix. In addition to callsite revalidation opt-out, we would greatly benefit from callsite revalidation opt-in. |
Beta Was this translation helpful? Give feedback.
-
tl;dr
Background
After actions are called, for any reason, a revalidation is automatically initiated. You can opt-out of that revalidation with the route
shouldRevalidate
property. This works great for a lot of cases and is familiar to geriatric React developers like me who remembershouldComponentUpdate
.One way to think about our current “revalidation opt-out” is that it is part of a routes “definition”, or a “definition site opt-out”. It doesn’t matter what triggered the revalidation, the route’s definition gets to decide if it wants to participate in revalidation. This is good because the idea is that developers can look at what the
loader
uses in order to define the route’sshouldRevalidate
. If it uses a certain search param, or url params, or loads data related to some special formData going to the action, all you have to know is the route’s own loader and not worry about the rest of the app.However, sometimes these
shouldRevalidate
functions can be tricky write with that model, and developers (including myself) often over-optimize (causing stale data bugs) or under-optimize (making it pointless).I’ve found in my own code that it’s often easier to answer the question “should this route revalidate?” at the “call site”: the place where a
<Form>
is rendered or afetcher.submit()
is called.Use Case:
A very easy case to think about is a newsletter sign up form at the bottom of multiple pages. If three routes are matching on a page then three revalidation requests will go out when the user submits the form. But, being subscribed to the newsletter is irrelevant to every loader in the app.
To get Remix to avoid making all three revalidation fetches for the newsletter form, each route must define a
shouldRevalidate
. Typically it’s far easier to check if theformData
is for the newsletter signup instead of what the loader needs. This is not the “definition site” model (what does this loader care about?) but is instead whack-a-mole for every route for every action that is irrelevant to loaders.Open questions:
<Link> <Form> fetcher.load
Beta Was this translation helpful? Give feedback.
All reactions