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
When using mutate from const { mutate } from 'swr'; to globally enforce a revalidation,
then the mutate is silently ignored for those cases where a consuming useSWR hook useSWR(key) is not mounted.
This renders the global mutate method as unreliable because a developer can never be sure that the cache marked by the key is actually marked as stale and the content is refetched.
Expected Behavior
When calling mutate from const { mutate } from 'swr'; with an arbitrary key the cache is marked stale and with the next mount of a consuming hook using that key the data is refetched.
When the cache wasn't marked as stale in the first place the cache would be used on mount
Repro Steps / Code Example
Given are one route component and two child components: ComponentA and ComponentB.
ComponentA fetches data and uses a cache key.
ComponentB contains a button that calls mutate.
ComponentA and ComponentB are never mounted at the same time.
When ComponentA is mounted - data is loaded and put into cache
Then we switch to ComponentB and press the button that calls "mutate" with the cache key of ComponentB.
Then we go back to ComponentA expecting to refetch, but it doesn't.
Additional Context
SWR version: all versions
The text was updated successfully, but these errors were encountered:
Bug report
Description / Observed Behavior
When using
mutate
fromconst { mutate } from 'swr';
to globally enforce a revalidation,then the mutate is silently ignored for those cases where a consuming useSWR hook
useSWR(key)
is not mounted.This renders the global
mutate
method as unreliable because a developer can never be sure that the cache marked by the key is actually marked as stale and the content is refetched.Expected Behavior
When calling
mutate
fromconst { mutate } from 'swr';
with an arbitrary key the cache is marked stale and with the next mount of a consuming hook using that key the data is refetched.When the cache wasn't marked as stale in the first place the cache would be used on mount
Repro Steps / Code Example
Given are one route component and two child components: ComponentA and ComponentB.
ComponentA fetches data and uses a cache key.
ComponentB contains a button that calls mutate.
ComponentA and ComponentB are never mounted at the same time.
Additional Context
SWR version: all versions
The text was updated successfully, but these errors were encountered: