-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always call onSuccess even with deduping? #1580
Comments
Thanks for opening this! By definition |
Thanks for the suggestion! I updated to I feel like this is a common enough use-case that there should be a separate callback that always gets called, even if it was deduped. |
I realized that I misunderstood your original message and it’s indeed a problem. Will figure out a way to fix it! |
Running into this issue still. Any update on when or how it might be resolved? |
@shuding is there any update on this? I'm getting a similar issue here and it's breaking my whole app. |
Issue is still happening. code sandbox to reproduce: |
React Query claims that |
I faced the same issue. In short, the solution for me was to disable deduping globally. I put this inside my // Disables deduping. Mandatory for requests that modify data, otherwise we can end up
// with broken frontend states when users are interacting quickly with the application.
dedupingInterval: 0, In my case, there is no valid case for deduping. The "read" requests I do are cached and rarely revalidated, but the "write" requests can happen in a quick succession. An example is that you can log in, log out and log in again in less than 2 s, the default I honestly think that deduping should be disabled by default, as it can be very misleading. Caching is already enabled by default, for most users it will be enough. I do not have an strong opinion on whether Note that I tried applying @isBatak’s suggestion of using useEffect(() => {
if (data) {
actualLogoutLogicLikeClearingAnInMemoryToken();
}
}, [data]); then once a first |
@BertrandBordage - From our perspective, we rely on deduping fairly heavily. For example, three different components that are all mounted at different places in the component tree might need the same information; it's convenient to assume / rely on deduping and treat If I understand your issue correctly, the rapid sequential requests are getting deduped even though there are mutation calls interspersed? If so, that sounds like it may be worth raising as a separate issue - mutation should override any dedupe interval. |
@joshkel Yes, it's somewhat related to mutations, but not necessarily. It's related to queries that modify data on the backend, so roughly POST/PUT/PATCH requests, which can be done with In my case it's always through |
Sorry that I went slightly off topic… The problem I faced was not It was a bug with the way the cache gets "cleared" that dedupes |
I have also encountered the same issue where if a user does a back button journey to the page within the 2 second deduping interval then Is there any other alternative |
I'm also running into a similar issue where I'm calling an async fetch in the |
It sounds like there should be a separate option instead of |
Bug report
Description / Observed Behavior
In some scenarios, I'd expect onSuccess to be called, but it doesn't. E.g. a route "/foo" populate the state inside SWR's onSuccess. If I quickly navigate /foo -> /other -> /foo before the request from the first /foo finishes fetching, the onSuccess from the second /foo won't run. The result is that the state in the second /foo remains the initial state.
Expected Behavior
Since the first /foo already unmounted, I'd expected the onSuccess from the second /foo to run. Alternatively, there should be a way for configure SWR so onSuccess always runs, even if the request was deduped.
Additional Context
SWR version: 1.0.1
The text was updated successfully, but these errors were encountered: