Overriding endpoints with Redux Toolkit Query and Vite HMR

651 Views Asked by At

I am using Redux Toolkit Query in a Vite project, and getting the typical warnings about overriding endpoints when the store HMR reloads.

called 'injectEndpoints' to override already-existing endpointName {NAME} without specifying 'overrideExisting: true'

As seen in this GitHub issue, a potential fix was suggested to set overrideExisting during a Webpack HMR reload. This would sidestep the issue by allowing endpoints to be overridden "silently" when expected (ie. during HMR reload). However, this fix does not work in Vite, as Vite HMR operates differently. I am hoping to get a fix for Vite's HMR workflow, but have been unable to find anything anywhere.

// Add to `injectEndpoints` call
overrideExisting: module.hot?.status() === "apply"

How can I only enable overriding existing RTK Query endpoints when the refresh/override was triggered by Vite HMR?

P.S. Not overriding existing endpoints certainly explains why I often need to hard refresh to actually notice changes made to RTK Query endpoints...

0

There are 0 best solutions below