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 a custom compare function and the comparison returns true, the data returned correctly keeps its current value, but the cached value still updates. This causes data to use the last received value when the component remounts and not the intended initial value we wanted to cache.
Expected Behavior
From reading the documentation I was expecting the cache to be persisted if a comparison returns true.
click "force revalidate" to... force some revalidates, and check data is correctly persisted.
click unmount to unmount the component
click mount again and check that data value is not the previously persisted value but the value of the last call
Additional Context
In my use case, the server response contains urls of images with timestamps that I want to exclude from the data diff in order to avoid re-downloading images the browser has in disk cache.
swr v0.4.0
The text was updated successfully, but these errors were encountered:
Unfortunately my real use case is a bit more nuanced and I actually need the timestamp and other variable parts of the response to use in my component. The compare feature is exactly what I need to update the cache conditionally.
Bug report
Description / Observed Behavior
When using a custom
compare
function and the comparison returnstrue
, thedata
returned correctly keeps its current value, but the cached value still updates. This causesdata
to use the last received value when the component remounts and not the intended initial value we wanted to cache.Expected Behavior
From reading the documentation I was expecting the cache to be persisted if a comparison returns true.
Repro Steps / Code Example
https://codesandbox.io/s/swr-using-compare-zn185?file=/src/App.tsx
data
is correctly persisted.data
value is not the previously persisted value but the value of the last callAdditional Context
In my use case, the server response contains urls of images with timestamps that I want to exclude from the data diff in order to avoid re-downloading images the browser has in disk cache.
swr v0.4.0
The text was updated successfully, but these errors were encountered: