tanstack-fetch 2.2.1 adds no new features. I went through every entry point (core, /sse, /trpc, the framework adapters, DevTools, and the CLI) and fixed 31 bugs. Each fix has a regression test.
npm install tanstack-fetch@2.2.1
If you haven't seen it before: tanstack-fetch is a small, typed fetch client built for TanStack Query. It has guides for React, Vue, Next.js, Nuxt, Solid, Svelte/SvelteKit, Angular and TanStack Start.
Here are the fixes most likely to have affected you.
1. A relative baseUrl actually works now
const api = createFetch({ baseUrl: '/api' })
await api.get('/users')
// 2.2.0 โ TypeError: Invalid URL
// 2.2.1 โ GET https://your.site/api/users
In the browser it resolves against location.href. On the server you get a clear error asking for an absolute baseUrl, so it no longer fails with a vague message.
2. Retries no longer re-send your POST by accident
Three fixes:
-
Interceptor errors thrown in
onResponse/onResponseError, such as anonUnauthorizedredirect, were wrapped asNETWORK_ERRORand could be retried, which meant re-sending a POST. They now propagate unchanged and are never retried. -
controller.abort(reason)was treated as a network error and retried. It now rejects with yourreason, with no retry. -
{ action: 'drop' }inonRequestwas typed but ignored. It now rejects withREQUEST_DROPPED, andfetchis never called.
3. SSE resume does what its name says
Before this release, only a bad status at connect time went through the reconnect path. A mid-stream drop went straight to your code, and Last-Event-ID was never sent.
const api = createFetch({ baseUrl, plugins: ['sse-resume'] })
for await (const event of api.sse<Order>('/orders/stream')) {
// after a drop: reconnects after 1s with Last-Event-ID: 7, continues at event 8
}
Other SSE fixes:
-
api.sse('/chat', { body: { prompt } })now sends a POST with the body. Before, it sent a GET and dropped the body. - The parser now handles
\r\nsplit across chunks,id:-only blocks and baredatalines. -
onSseCloseruns exactly once, andclose()during the reconnect wait actually stops the reconnect.
4. SSR leaks in Vue/Nuxt and Svelte
- Vue/Nuxt
useSse/useWswere opening connections during SSR. They now connect only in the browser. - Svelte's
setFetchClient()stored the client in a module-level variable, shared across SSR requests. On the server, the client now comes from Svelte context only.
5. A DevTools XSS
The DevTools panel used innerHTML to render values that partly came from a response header (x-tanstack-fetch-mock), so a server could inject script into it. Every element is now built with textContent.
6. Codemods that produce working code
-
migrateconverts ky'sky.get(url).json<User>()toapi.get<User>(url). - It renames axios
params:toquery:only at the top level of the config, not inside request bodies. - It puts the new import after
'use client'. -
generate(OpenAPI) now outputs valid TypeScript: it quotes keys like'content-type'and de-duplicates colliding names.
Behaviour changes to check
- Interceptor errors are rethrown as-is, with no retry.
-
abort(reason)rejects withreason. - An SSE call with a
bodysends a POST. -
sse-resumereconnects after drops and 5xx responses. - A WebSocket's reconnect counter resets only after 5s of stable connection.
- A relative tRPC URL on the server now throws.
Cost
The core grew by about 260 bytes gzip (3.71KB โ 3.97KB).
Known limits
Solid, Svelte and Angular useSse / useWs still don't re-subscribe when path or options change. That's planned for the next minor release.
๐ Full release notes ยท โญ GitHub ยท ๐ฆ npm ยท ๐ Docs
If you use it, I'd love to hear which of these bugs you'd already run into. Issues and stars are very welcome.
Top comments (0)