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

Global mutate does not invalidate useSWRInfinite requests #3015

Open
colemars opened this issue Sep 5, 2024 · 1 comment
Open

Global mutate does not invalidate useSWRInfinite requests #3015

colemars opened this issue Sep 5, 2024 · 1 comment

Comments

@colemars
Copy link

colemars commented Sep 5, 2024

Bug report

Description / Observed Behavior

I have a series of pages fetched via useSWRInfinite. I am attempting to invalidate them via the global mutate function. In testing, I did simply

mutate((k) => {
        console.log('k', k)
        return true
      })

to observe all cache keys and, theoretically, trigger invalidations for all of them as well (again, for testing).

However, despite seeing the relevant cache keys logged - the requests from useSWRInfinite did not revalidate.

Expected Behavior

If I run

mutate((k: any) => {
        console.log('k', k)
        return true
      })

I would expect all cached requests to revalidate, as described in the docs.

Repro Steps / Code Example

I took the example from the docs and just replaced mutate with the above function using global mutate.

https://codesandbox.io/p/sandbox/swr-infinite-forked-h7y9zw?file=%2Fsrc%2FApp.js%3A68%2C14

Additional Context

^2.2.5
Add any other context about the problem here.

@colemars
Copy link
Author

colemars commented Sep 5, 2024

    for (const key of it) {
      if (
        // Skip the special useSWRInfinite and useSWRSubscription keys.
        !/^\$(inf|sub)\$/.test(key) &&
        keyFilter((cache.get(key) as { _k: Arguments })._k)
      ) {
        matchedKeys.push(key)
      }
    }

Would y'all be open to adding a way to access the special keys in the global mutator? It seems not desirable that infinite keyed requests cannot be globally mutated via partial matching with the filter method.

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

1 participant