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
We have been observed the functionality of onError and onErrorRetry callbacks has changed in the minor 1.1.0
We have cases in our apps where we call useSWR with the same cache key for multiple times, sometimes just for reading data, other times for reading data and handling error scenarios.
Before 1.1.0 ( before #1522) , we could see that all the hooks callbacks were being called back. And that was useful for when you use the same useSWR cache key multiple times in the same page. Useful for when you have multiple panels in the same page - and you want the components to get the data independently from the cache - but you would want to handle differently the error retry in each panel.
Since 1.1.0 only the first rendered hook is being called back resulting that only the first component that uses the same cache key could change the UI in case of onError is fired or onErrorRetry
Expected Behavior
If the useSWR hook has the onError and onError retry option - I would expect it to actually be called back in all the call sites.
Repro Steps / Code Example
constsameFetcher=()=>Promise.reject('Ooups');constComponentOne=()=>{const{ data }=useSWR('same-key',sameFetcher,{onError: (error)=>{console.log('ComponentOne onError fired',error)// only this is fired},onErrorRetry: (error,_key,_config)=>{console.log('ComponentOne onErrorRetry fired',error,_key,_config)// only this is fired}})return<pre>{data}</pre>}constComponentTwo=()=>{const{ data }=useSWR('same-key',sameFetcher,{onError: (error)=>{console.log('ComponentTwo onError fired',error)// this is not called back},onErrorRetry: (error,_key,_config)=>{console.log('ComponentTwo onErrorRetry fired',error,_key,_config)// this is not called back}})return<pre>{data}</pre>}constApp=()=>{return<div><ComponentOne/><ComponentTwo/></div>}
Additional Context
SWR version. 1.3.0
The text was updated successfully, but these errors were encountered:
Bug report
Description / Observed Behavior
We have been observed the functionality of onError and onErrorRetry callbacks has changed in the minor 1.1.0
We have cases in our apps where we call useSWR with the same cache key for multiple times, sometimes just for reading data, other times for reading data and handling error scenarios.
Before 1.1.0 ( before #1522) , we could see that all the hooks callbacks were being called back. And that was useful for when you use the same useSWR cache key multiple times in the same page. Useful for when you have multiple panels in the same page - and you want the components to get the data independently from the cache - but you would want to handle differently the error retry in each panel.
Since 1.1.0 only the first rendered hook is being called back resulting that only the first component that uses the same cache key could change the UI in case of onError is fired or onErrorRetry
Expected Behavior
If the useSWR hook has the onError and onError retry option - I would expect it to actually be called back in all the call sites.
Repro Steps / Code Example
Additional Context
SWR version. 1.3.0
The text was updated successfully, but these errors were encountered: