Ask

alt-tabbing back fires 63 xhr requests on tanstack query v5, where do i look

Two separate things are happening and you are treating them as one.

The burst: focus refetching only touches queries that are active and stale. Your staleTime is the default 0, so every active query is stale the instant it resolves, so all of them refetch. Six panels with three or four queries each, plus dependents that fire once their parent resolves, gets you to 60-odd without anything being wrong. Set a real staleTime and most of it evaporates:

defaultOptions: { queries: { staleTime: 30_000, gcTime: 5 * 60_000 } }

A dashboard where data one refresh old is unacceptable is a dashboard that wants a socket, not polling on focus.

The 21 entries: inactive ones (0 observers) are leftovers held for gcTime, and they do not refetch on focus. They are not sending requests. They are just evidence that something in your key changes more often than it should - which is worth chasing, but separately from the burst.

71 · in/react-data-fetching ·

alt-tabbing back fires 63 xhr requests on tanstack query v5, where do i look

Not quite - query keys are compared by a deterministic hash, not by reference. hashKey stringifies with sorted object keys, so a fresh literal with the same contents produces the same hash and the same cache entry. Memoising the object changes nothing here. The reason there are 21 entries is that the contents genuinely differ, which is why the hash dump above is the right diagnostic.

27 · in/react-data-fetching ·

Six half used candle fragrance oils, can any of them go into reed diffusers?

Practical version, from a couple of hundred diffusers made for a market stall. You need a carrier, not just the oil. Neat fragrance barely climbs the reeds and what does climb evaporates unevenly. Most people use a diffuser base sold for the purpose, and the usual working range lands somewhere around a quarter to a third fragrance by weight with the rest base. Fibre reeds move liquid noticeably faster than natural rattan, so with rattan expect a slower, quieter throw and tell people to flip the reeds weekly. A 100ml bottle with eight fibre reeds lasted me about two months in a normal sized room.

69 · in/candlemaking ·

invalidateQueries resolves but the table keeps the old row until i navigate away

If the cache does turn out to hold the stale value, look at your optimistic update. The classic shape is:

onMutate: async () => { const prev = qc.getQueryData(key); ...; return { prev } }
onError: (e, v, ctx) => qc.setQueryData(key, ctx.prev)
onSettled: () => qc.invalidateQueries({ queryKey: key })

If anything in that chain runs after the refetch resolves - a rollback firing on a request that actually succeeded but returned a non-2xx body, a second in-flight mutation settling late - you get exactly this: fresh data on the wire, stale data in the cache, and no error anywhere. Log dataUpdatedAt on every write and the ordering becomes obvious.

86 · in/react-data-fetching ·

Year 6 ratio homework: my method gets the right answer and her teacher marks it wrong

Parent of two, learned bar models under protest, now use them myself for anything with mixtures or percentages. Draw the total as a strip, cut it into the number of parts in the ratio, label one part, done. The genuinely useful thing is that when the question changes shape - one part is 12 more than another, find the total - the drawing still works and cross multiplication needs rearranging first.

88 · in/math-help ·

My hens are five and lay maybe one egg a week each - what do people actually do at this point?

This is just what the curve looks like. Mine peak in their first full laying year, drop noticeably in year three, and by five they are ornamental with occasional bonuses. The birds themselves usually have years left in them, I have had hens reach eight and one hybrid make ten, though hybrids bred hard for output tend to have shorter, rougher retirements than heritage breeds. I run a rolling flock: two new pullets every second year, so I always have someone laying and nobody has to make a decision on a specific bird.

121 · in/backyard-hens ·

coming from useEffect fetching, is one query key per screen too coarse

Key by the resource and its parameters, not by the place it is displayed. ['orders', { status, page }] and ['customer', id].

The reason is that screens are not unique owners of data. The moment two screens both show the customer, screen keys give you two copies that go stale independently, and updating one leaves the other wrong. Resource keys give you one entry that both screens observe, so a single invalidation fixes both, and the second screen renders instantly from cache instead of refetching.

Invalidation stays just as easy because matching is by prefix: invalidateQueries({ queryKey: ['orders'] }) hits every orders query regardless of the filters after it. That prefix behaviour is the whole design and it is what screen keys throw away.

121 · in/react-data-fetching ·

Why is versus written v in case names and vs everywhere else, and what did it mean in Latin

Small correction to the idea that English borrowed it once and kept it. It is better described as several borrowings from a living professional Latin, because legal Latin stayed in active use in English courts long after Latin stopped being a general written language here. That is also why the word never went through the usual sound changes you would expect from a fifteenth century loan, and why it still looks like an undigested Latin word today: it never really stopped being one.

71 · in/word-origins ·

zustand or leave it in the query cache - 2 devs, 40 screens, offline edits

The framing that made this stop being an argument on my team: state is either owned by the server or owned by the client, and the question is never which library, it is which of those two a piece of data is. A job record is server-owned even when you are editing it offline - you are holding a pending intent, not the truth. Drafts, filters and UI state are client-owned.

Once you say it that way, your current split is already correct and the proposal is to break it. Keep the three Zustand stores small and stop worrying that they are small.

143 · in/react-data-fetching ·

Mail order calathea arrived on day nine, limp and yellow - nurse it or ask for a refund?

I order a lot and my first hour routine is fixed: unbox immediately, check for pests before it goes near anything else, water thoroughly into the sink and let it drain properly, then a bright spot away from radiators and direct sun, and a bag or a clear box over it for a week if it is a humidity fussy species. Nothing else for at least a month. Most plants that look dead on arrival are dehydrated rather than dead, and the ones that do not recover usually declare themselves within ten days.

87 · in/houseplant-rescue ·