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
I observe that if I provide a fallback cache to SWRConfig, using useSWRMutation will always return undefined and ignoring the cache config.
I saw that internally useSWRMutation reuse the middleware system and discovered that it does call useSWRNext under the hook. I think it could explain why this feature is lost.
Expected Behavior
I assume that useSWRMutation has a same behavior as useSWR so that if a fallback value is provided, then it should return the fallback value before mutate. It will be very useful in a scenario that a page is loaded by SSR but also there is a need for manual mutation to update the data at client side.
Repro Steps / Code Example
a simple example fork from swr demo
I expect the fallback data should be rendered first, but user can manually update the data as well with the triggering the button
Additional Context
This issue is obeserved at swr 2.0.0
I am not sure if this is an intended behavior or not but I hope that my judgement and understanding to swr is correct. Plz point out if I have missed anything. Thanks.
This discussion was converted from issue #2345 on January 24, 2023 15:56.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Bug report
Description / Observed Behavior
I observe that if I provide a fallback cache to SWRConfig, using
useSWRMutation
will always returnundefined
and ignoring the cache config.I saw that internally
useSWRMutation
reuse the middleware system and discovered that it does calluseSWRNext
under the hook. I think it could explain why this feature is lost.Expected Behavior
I assume that useSWRMutation has a same behavior as useSWR so that if a fallback value is provided, then it should return the fallback value before mutate. It will be very useful in a scenario that a page is loaded by SSR but also there is a need for manual mutation to update the data at client side.
Repro Steps / Code Example
a simple example fork from swr demo
I expect the fallback data should be rendered first, but user can manually update the data as well with the triggering the button
Additional Context
This issue is obeserved at swr 2.0.0
I am not sure if this is an intended behavior or not but I hope that my judgement and understanding to swr is correct. Plz point out if I have missed anything. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions