-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stale data when mutating key with no registered updaters #751
Comments
you can do async function updateItem(data) {
const response = await request(URL_TO_ITEM, data)
mutate(URL_TO_ITEM)
const list = await request(URL_TO_ITEM_LIST)
mutate(URL_TO_ITEM_LIST, list)
return response
} |
Sure, that would work. But then again, what kind of signal does a
It seems that calling If that's intended then perhaps we need an explicit |
I think this issue is fixed by: #1498 |
Yeah I think so, thanks @nataliemarleny! |
Bug report
Description / Observed Behavior
I have a list of items and a page for each item like so:
While the
<Item />
component is rendered, the<ItemList />
component is not redered and vice versa. The<Item />
component has fields allowing users to modify it and these changes should be reflected in the list. Therefore the update function looks something like this:When this function is called a request to revalidate the item data is sent to
URL_TO_ITEM
and no request is sent toURL_TO_ITEM_LIST
since the<ItemList />
component is not rendered anduseSWR
finds no updaters, which is expected. Now if we navigate to show the<ItemList />
still no request toURL_TO_ITEM_LIST
will be sent, rendering it with its previous (stale) data as if nomutate(URL_TO_ITEM_LIST)
call was made in the update function at all.Expected Behavior
Calling
mutate()
as described above should evict the data under the given key from cache when there are no updaters (no components using it), so that it does not remain stale.Repro Steps / Code Example
I am currently not able to create a repro case since I am a little bit overwhelmed irl. If the description above is not clear enough, please let me know and I will provide a repro case ASAP.
However I took a quick look at the source code and it seems to me that when the this condition results to
false
andelse
case should probably remove the stale data from cache. This will make it so that the next time<ItemList />
is rendered it will find no cached data available and will correctly fetch new data from server. I could be completely wrong though.Additional Context
SWR version: 0.3.8
The text was updated successfully, but these errors were encountered: