React Router 7 revalidates loader on cart mutation – how to prevent unnecessary 3rd party API refetch?

Hi everyone,

I’m working on a Shopify Hydrogen store using React Router v7 and I’m running into an issue with unwanted revalidation when performing cart actions.

Scenario
On my product page, I fetch data from third-party APIs
Whenever a user adds an item to the cart:

POST /cart

React Router revalidates the product route loader, which causes:
Product route to reload
All useFetcher calls to re-run
My external APIs to be called again unnecessarily

For testing i tryied to disable revalidation completly
export function shouldRevalidate() { return false;}

Is there any way I could prevent 3rd party api refetch here ?
Thanks for any response

Hey Erik,

What was the result of your test?

Adding the shouldRevalidate to your product route should prevent the loader from revalidating when adding to cart.

export function shouldRevalidate({

  formMethod,

formAction,

}: ShouldRevalidateFunctionArgs) {

if (

    formMethod === 'POST' &&

    (formAction === '/cart' || formAction?.includes('/cart'))

  ) {

return false;

  }



return true;

}

Hi J,
thanks for taking your time to response, seems like you are unicorn.
Iam sure I have tryied your suggested solution, but for sanity check I’ll check again.
once again thanks for the reply