Skip to content
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

fix: deduplicate identical mutations #141

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/app/query-client/use-query-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ const useQueryClient = () => {
},
})

const mutationCache = queryClient.getMutationCache()
// prevent duplicate mutations from being stored in cache
mutationCache.subscribe((event) => {
if (event.type !== 'updated') {
return
}
const { mutation } = event
const duplicateMutation = mutationCache.find({
mutationKey: mutation.options.mutationKey,
// ensure previous mutation was fired before this
// (mutationId is an incremental integer)
predicate: (currMutation) =>
currMutation.mutationId < mutation.mutationId,
})
if (duplicateMutation) {
mutationCache.remove(duplicateMutation)
}
})

return queryClient
}

Expand Down