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
In here the cache is being invalidated two times if queryFulfilled rejects resulting in two network requests:
exportconstauthApi=api.injectEndpoints({endpoints: (build)=>({getSessions: build.query<GetSessionsResponse[],void>({query: ()=>"auth/sessions",transformResponse: (response: {data: GetSessionsResponse[]})=>response.data,providesTags: ["Sessions"],}),deleteSession: build.mutation<void,string>({query: (token)=>({url: `auth/sessions/${token}`,method: "DELETE",}),onQueryStarted: async(token,{ dispatch, queryFulfilled })=>{dispatch(authApi.util.updateQueryData("getSessions",undefined,(draft)=>{returndraft.filter((session)=>session.token!==token);}));try{awaitqueryFulfilled;}catch{// Invalidate cache tag on failure to re-fetch truly up-to-date datadispatch(authApi.util.invalidateTags(["Sessions"]));}},invalidatesTags: ["Sessions"],}),}),});
Would it be ok to add dispatch(authApi.util.invalidateTags(["Sessions"])); on the success result as well and remove invalidatesTags altogether?
...
try{awaitqueryFulfilled;dispatch(authApi.util.invalidateTags(["Sessions"]));}catch{// Invalidate cache tag on failure to re-fetch truly up-to-date datadispatch(authApi.util.invalidateTags(["Sessions"]));}},
...
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
-
In here the cache is being invalidated two times if
queryFulfilled
rejects resulting in two network requests:Would it be ok to add
dispatch(authApi.util.invalidateTags(["Sessions"]));
on the success result as well and removeinvalidatesTags
altogether?Beta Was this translation helpful? Give feedback.
All reactions