{{ message }}
fix(preact-query): do not go into optimistic fetching state when not subscribed - #11259
Open
giaBaoJS wants to merge 1 commit into
Open
fix(preact-query): do not go into optimistic fetching state when not subscribed#11259giaBaoJS wants to merge 1 commit into
giaBaoJS wants to merge 1 commit into
Conversation
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
subscribed: falseis broken in@tanstack/preact-query. A hook that opts out of subscribing still reportsisFetching: true/fetchStatus: 'fetching'on first render, even though no observer is ever attached and thequeryFnis never called.The Preact adapter was forked from React in #9935 (Feb 2026) and then missed two fixes that landed on the React side afterwards:
useBaseQueryuseQueriesBoth hooks in
preact-querystill set_optimisticResults = 'optimistic'unconditionally. IncreateResult, that branch computesfetchOnMount = !mounted && shouldFetchOnMount(query, options); with no listeners attached,mountedisfalseand the result is optimistically flipped intofetchState— a fetch that will never happen.useQueriesadditionally leftsubscribedout of theuseMemodependency array, so toggling it did not recompute the defaulted options.Fix
Port the two upstream changes verbatim: derive
subscribedonce, use it to gate_optimisticResults(undefinedwhen not subscribed), add it to theuseQueriesdependency array, and reuse it forshouldSubscribe. The diff is identical in shape toreact-query's currentuseBaseQuery.ts/useQueries.ts.Tests
Two regression tests, mirroring the ones added upstream:
useQuery.test.tsx— added to the existingsubscribeddescribe blockuseQueries.test.tsx— the Preact counterpart of the test from fix(react-query): keep unsubscribed useQueries idle #11130Both are synchronous, so there is no timer race.
Validation
Run from the repo root with
pnpm nx run @tanstack/preact-query:test:lib --skip-nx-cache.main: 34 files / 524 tests passing, no type errors.useBaseQuery.tsfails just theuseQuerytest; reverting onlyuseQueries.tsfails just theuseQueriestest. Reverting both fails both, withisFetching: true/fetchStatus: fetchingrendered wherefalse/idleis expected.test:types,test:eslint,test:buildandbuildfor the package, plusprettier --checkon the touched files.Summary by CodeRabbit
Bug Fixes
isFetching: falseand an idle fetch status.Tests
useQueryanduseQueries.