reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.74k stars 1.18k forks source link

Safari request/response local override is not working with rtk query #3550

Closed nouman91 closed 1 year ago

nouman91 commented 1 year ago

Hi, I am trying to override the server response with local override and I have noticed it does not work with RTK query. My use case is the server does not have the data and I want to load data with Safari local override. But the trouble is RTK query can't seem to understand it and does not return the overridden data.

I am sure this has been answered somewhere but I was not able to find it.

markerikson commented 1 year ago

We just use the built-in fetch API. I have no idea how Safari's overrides work, but I don't think it's going to be anything we have control over in RTKQ.

nouman91 commented 1 year ago

Hmm.. Thank you for your quick reply. It seems I have to do some digging around to understand it.

Brief description Safari local override: You can override the response returned by the server with whatever you want and instead of serving the server response it will serve you the local response. Override

I just did a quick test: API-1 with rtk query; Does not work with local override always returns the original cached server response. API-2 without rtk query: Works as expected with local override.

EskiMojo14 commented 1 year ago

as in, making a normal fetch request returns your override?

edit: I just reread

RTKQ intentionally returns the cached result, that's what a cache does. If you want to clear the cache when you apply an override then you might need to dispatch resetApiState,

nouman91 commented 1 year ago

Thank you! I think that's what I need in this case as data is cached. Looking into integrating resetApiState for my use case.

nouman91 commented 1 year ago

Is there any way I can disable the cache completely?

phryneas commented 1 year ago

RTK Query is the cache, it doesn't do a lot beyond that. So, removing RTK Query would do that. But honestly, if you don't manually persist your Redux store somewhere: press F5 and you start again with an empty cache.

nouman91 commented 1 year ago

Closing this issue as it was related to caching. Thanks for the quick help, I really appreciate it.