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 recently updated my project to 0.25 from 0.20 and observed some unexpected behavior in request cancelations.
Intended outcome
Network requests on watched queries are not interrupted by cache updates.
Actual outcome
If a cache update comes in while a server fetch is in flight, the server fetch is canceled, and a .failure is sent to the completion handler.
How to reproduce the issue
Watch a query with a cache policy that includes a server fetch
While the server fetch is in flight, modify a dependent key in the cache in a read/write transaction
The fetch is canceled
I believe this behavior was introduced by #1012 in 0.22
It appears that if a dependent key of the watcher is written to, a cache fetch is triggered, effectively canceling the in-flight server fetch, and issuing a .failure to the completion handler.
Here is a concrete example of how this is playing out in my project, which features a list of chat conversations:
If some conversations are unread, the user can navigate to a carousel of unread conversations. This list of conversation was previously fetched and is available in the cache.
When the users navigates to the carousel of unread conversations:
UnreadConversationQuery is watched with .returnCacheDataAndFetch
The cached list is returned and the first conversation displayed. The server fetch is issued.
The first conversation marks itself as read
isRead is set to true optimistically in the cache for this conversation
Since UnreadConversationQuery depends on this same isRead key, the server fetch is canceled and replaced by a cache fetch.
The watch result handler is called with a .failure
The text was updated successfully, but these errors were encountered:
I recently updated my project to
0.25
from0.20
and observed some unexpected behavior in request cancelations.Intended outcome
Network requests on watched queries are not interrupted by cache updates.
Actual outcome
If a cache update comes in while a server fetch is in flight, the server fetch is canceled, and a
.failure
is sent to the completion handler.How to reproduce the issue
I believe this behavior was introduced by #1012 in
0.22
It appears that if a dependent key of the watcher is written to, a cache fetch is triggered, effectively canceling the in-flight server fetch, and issuing a
.failure
to the completion handler.Here is a concrete example of how this is playing out in my project, which features a list of chat conversations:
UnreadConversationQuery
is watched with.returnCacheDataAndFetch
isRead
is set to true optimistically in the cache for this conversationUnreadConversationQuery
depends on this sameisRead
key, the server fetch is canceled and replaced by a cache fetch..failure
The text was updated successfully, but these errors were encountered: