Skip to content
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

Deduplication not working properly #3013

Open
tastydev opened this issue Sep 1, 2024 · 2 comments
Open

Deduplication not working properly #3013

tastydev opened this issue Sep 1, 2024 · 2 comments

Comments

@tastydev
Copy link

tastydev commented Sep 1, 2024

Bug report

Description / Observed Behavior

I am experiencing requests to the same endpoint/cache key within the dedupeInterval and i don't think this is the expected behaviour?
In my code example posted below, you can see that 2 mounted react components are using the same custom hook to fetch a client ip.
The custom hook is using swr to fetch the ip.
The component registers an interval to simulate "same time" network requests to the same swr cache key.

Expected Behavior

I would expect to only see 1 request, if two components are using the same swr key while calling mutate within the dedupeInterval time span.

Repro Steps / Code Example

I made an example with my described behaviour here: CodeSandbox SWR Dedupe Example

  1. Open Dev Tools
  2. Open Network Tab
  3. See 2 requests to the same endpoint/key at the same time

Additional Context

SWR version: 2.2.5 but also seeing this in 1.3.0

@tastydev tastydev changed the title Deduplication not working Deduplication not working properly Sep 1, 2024
@pke
Copy link

pke commented Sep 2, 2024

Related? #1786 (comment)
I'm afraid this works as designed. How about not using mutate but instead just 2 components rendering the same key? Will it duplicate?

@tastydev
Copy link
Author

tastydev commented Sep 4, 2024

It is related, but i am just not understanding why this might be the intended behavior. If code executes X mutates on the same key (while revalidate is true) for whatever reason there is no use case in my opinion why SWR should not deduplicate this. In my opinion mutates have to be queued or paused within the deduplication time span while one mutate is refreshing the cache with a request. After the request resolves, the other mutates are reading the cache. Obviously SWR is not doing this.... Is this a design flaw in SWR or are we just expecting to much from the library? What are your thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants