Skip to content
Merged
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
26 changes: 26 additions & 0 deletions packages/query-core/src/__tests__/mutations.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1171,4 +1171,30 @@ describe('mutations', () => {
expect(unhandledRejectionFn).toHaveBeenNthCalledWith(4, newSettledError)
})
})

test('should not remove mutation when one observer is removed but another still exists', async () => {
const observer1 = new MutationObserver(queryClient, {
gcTime: 10,
mutationFn: () => sleep(10).then(() => 'data'),
})
const unsubscribe1 = observer1.subscribe(() => undefined)

observer1.mutate()
await vi.advanceTimersByTimeAsync(10)

expect(queryClient.getMutationCache().getAll()).toHaveLength(1)

const mutation = queryClient.getMutationCache().getAll()[0]!
const observer2 = new MutationObserver(queryClient, {
gcTime: 10,
mutationFn: () => sleep(10).then(() => 'data'),
})
mutation.addObserver(observer2)

unsubscribe1()

await vi.advanceTimersByTimeAsync(10)

expect(queryClient.getMutationCache().getAll()).toHaveLength(1)
})
})
Loading