Released 5.105.1 emits unhandled cancellation after offline paused refetch #12484
Problem#
With @tanstack/query-core 5.105.1, refetchQueries using throwOnError: true resolves while a query is paused offline, but clearing the client afterward emits an unhandled CancelledError. The latest npm latest tag is still 5.105.1 (checked 2026-11-01), so the released package remains affected.
This is a new report after #12479 was closed as not planned. I understand the maintainer response that the fix is not released yet. Fix #12442, for #12441, merged after 5.105.1 was published; this report tracks the still-reproducible behavior in the latest published package and does not claim that the merged fix is ineffective.
Reproduce#
Reproduced with Node.js 26.12.1. In an empty directory, run npm install @tanstack/query-core@5.105.1. Save the following as repro.mjs and run node repro.mjs:
import { QueryClient, onlineManager } from '@tanstack/query-core';
const errors = [];
const record = (error) => errors.push(error);
process.on('unhandledRejection', record);
const client = new QueryClient();
const queryKey = ['example'];
try {
await client.fetchQuery({ queryKey, queryFn: async () => 'value' });
onlineManager.setOnline(false);
await client.refetchQueries({ queryKey }, { throwOnError: true });
console.log('Fetch status:', client.getQueryState(queryKey).fetchStatus);
client.clear();
await new Promise((resolve) => setTimeout(resolve, 0));
console.log('Unhandled rejections:', errors.map((error) => error.message));
} finally {
onlineManager.setOnline(true);
client.clear();
process.off('unhandledRejection', record);
}
Actual / expected#
Actual output:
Fetch status: paused
Unhandled rejections: [ 'CancelledError' ]
Expected: cancelling the paused fetch after the public refetch promise has resolved does not produce an unhandled rejection. The public promise may retain its existing behavior of resolving immediately for paused queries.
Impact#
Applications that clear or replace a query client during offline operation can emit an unhandled rejection even though callers awaited refetchQueries.
Evidence and exposure#
This is a package-level reproduction on the latest published version, not a report of a production incident. The failure requires a paused fetch started with throwOnError: true followed by cancellation, such as client.clear().
TkDodo closed this
Sign in to join this conversation.