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
According to the documentation it is possible to mutate multiple items. I use that because some of my requests contain dynamic query parameter for pagination control, and in case of a newly added item I have to refresh the whole collection, hence all request independent of the actual page index. Because of that, I cannot simply pass a string as key, instead I use the matcher argument.
This works fine for useSWR with global mutation:
mutate((key)=>/^\/boards.*$/.test(key),null);
In addition I have a page with infinite loading that is using useSWRInfinite. Again I have to revalidate all pages of the collection. The documentation suggests to use mutate(unstable_serialize(getKey)) (I know it's unstable). This works well within the same component in which the useSWRInfinite call occurs. But now I have to revalidate across all pages globally. Sadly, unstable_serialize doesn't work with a matcher function or regex, only strings are supported.
I found out, that infinite key are prefixed with $inf$. So my idea was to skip unstable_serialize and use something like the following:
The infinite keys (Keys prefixed with $inf$) never seem to be handed over to the matcher function. The "normal" keys are handed over, but not the infinite keys. But the keys are definitely present in cache, I checked it and my workaround is based on it.
Expected Behavior
Maybe I missed something but I would expect, that the infinite keys would be handed over too, so the matcher function can deal with them. This way I wouldn't have to build a workaround.
Bug report
Description / Observed Behavior
According to the documentation it is possible to mutate multiple items. I use that because some of my requests contain dynamic query parameter for pagination control, and in case of a newly added item I have to refresh the whole collection, hence all request independent of the actual page index. Because of that, I cannot simply pass a string as key, instead I use the matcher argument.
This works fine for
useSWR
with global mutation:In addition I have a page with infinite loading that is using
useSWRInfinite
. Again I have to revalidate all pages of the collection. The documentation suggests to usemutate(unstable_serialize(getKey))
(I know it's unstable). This works well within the same component in which theuseSWRInfinite
call occurs. But now I have to revalidate across all pages globally. Sadly,unstable_serialize
doesn't work with a matcher function or regex, only strings are supported.I found out, that infinite key are prefixed with
$inf$
. So my idea was to skipunstable_serialize
and use something like the following:Problem:
The infinite keys (Keys prefixed with
$inf$
) never seem to be handed over to the matcher function. The "normal" keys are handed over, but not the infinite keys. But the keys are definitely present in cache, I checked it and my workaround is based on it.Expected Behavior
Maybe I missed something but I would expect, that the infinite keys would be handed over too, so the matcher function can deal with them. This way I wouldn't have to build a workaround.
Repro Steps / Code Example
Additional Context
SWR Version:
2.3.3
The text was updated successfully, but these errors were encountered: