react-query's HydrationBoundary just got fixed in #11137 to hydrate existingQueries (data for queries that are already in the cache and remounting) in a layout effect instead of a passive useEffect, since a remounting useQuery can subscribe and read the stale cached data before a passive effect runs, kicking off a refetch for data the dehydrated state already had.
packages/preact-query/src/HydrationBoundary.tsx has basically the same structure (same useMemo splitting new vs existing queries, same hydration queue) but still uses plain useEffect from preact/hooks for the final hydration:
useEffect(() => {
if (hydrationQueue) {
hydrate(client, { queries: hydrationQueue }, optionsRef.current)
}
}, [client, hydrationQueue])
Checked Preact's docs and useLayoutEffect from preact/hooks has the same semantics as React's version, runs synchronously after DOM mutations and before paint, so the same fix should carry over directly. isServer is already exported from @tanstack/query-core, which preact-query already imports hydrate from, so building the same isomorphic layout effect (isServer ? useEffect : useLayoutEffect) shouldn't need anything new.
Not sure if this was left out of #11137 on purpose (maybe preact-query gets less attention and just hasn't caught up yet) or just missed since it's a separate package, wanted to flag it either way since the race it fixes doesn't seem preact-specific at all.
react-query's
HydrationBoundaryjust got fixed in #11137 to hydrateexistingQueries(data for queries that are already in the cache and remounting) in a layout effect instead of a passiveuseEffect, since a remountinguseQuerycan subscribe and read the stale cached data before a passive effect runs, kicking off a refetch for data the dehydrated state already had.packages/preact-query/src/HydrationBoundary.tsxhas basically the same structure (sameuseMemosplitting new vs existing queries, same hydration queue) but still uses plainuseEffectfrompreact/hooksfor the final hydration:Checked Preact's docs and
useLayoutEffectfrompreact/hookshas the same semantics as React's version, runs synchronously after DOM mutations and before paint, so the same fix should carry over directly.isServeris already exported from@tanstack/query-core, which preact-query already importshydratefrom, so building the same isomorphic layout effect (isServer ? useEffect : useLayoutEffect) shouldn't need anything new.Not sure if this was left out of #11137 on purpose (maybe preact-query gets less attention and just hasn't caught up yet) or just missed since it's a separate package, wanted to flag it either way since the race it fixes doesn't seem preact-specific at all.