You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Throughout my current project, I am using conform for my form validation. One of its features is server-side form validation, which can occur onInput. When combining these with remix forms (I have only checked behavior with fetcher.Form, but I don't see why Form shouldn't have the same issue), lots of requests are made to the action for validation (expected and wanted), which causes (by default) all loaders for all currently active routes to be revalidated (expected, but not wanted). To avoid these unnecessary requests, I am using a simple shouldRevalidate function for all of my routes (see below for my helper function that still allows additional customization for when it's necessary).
This function is currently used on every route in my project.
It would be nice to be able to configure this default shouldRevalidate function somewhere, so I don't have to remember adding it to all routes.
I'm also open to hearing advice on alternative approaches if they exist.
exportfunctionshouldRevalidate_ignoreValidateIntent(fn?: ShouldRevalidateFunction,){return(args: ShouldRevalidateFunctionArgs)=>{try{if(args.formData!==undefined){constintent=args.formData.get("__intent__");if(intent!==null&&typeofintent==="string"){constvalue=JSON.parse(intent);if(typeofvalue==="object"&&value!==null&&hasOwnProperty(value,"type")&&value.type==="validate"){returnfalse;}}}}catch(e){// ignore, meaning fall back to default}returnfn===undefined ? args.defaultShouldRevalidate : fn(args);};}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Throughout my current project, I am using conform for my form validation. One of its features is server-side form validation, which can occur onInput. When combining these with remix forms (I have only checked behavior with
fetcher.Form
, but I don't see whyForm
shouldn't have the same issue), lots of requests are made to the action for validation (expected and wanted), which causes (by default) all loaders for all currently active routes to be revalidated (expected, but not wanted). To avoid these unnecessary requests, I am using a simpleshouldRevalidate
function for all of my routes (see below for my helper function that still allows additional customization for when it's necessary).This function is currently used on every route in my project.
It would be nice to be able to configure this default shouldRevalidate function somewhere, so I don't have to remember adding it to all routes.
I'm also open to hearing advice on alternative approaches if they exist.
Beta Was this translation helpful? Give feedback.
All reactions