Skip to content

fix(preact-query): do not go into optimistic fetching state when not subscribed - #11530

Open
RezaRahemtola wants to merge 1 commit into
TanStack:mainfrom
RezaRahemtola:fix/preact-unsubscribed-optimistic-state
Open

RezaRahemtola wants to merge 1 commit into
TanStack:mainfrom
RezaRahemtola:fix/preact-unsubscribed-optimistic-state

Conversation

@RezaRahemtola

@RezaRahemtola RezaRahemtola commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

useQuery with subscribed: false in preact-query reports isFetching: true on every render even though the observer is never attached and queryFn is never called.

useBaseQuery always sets _optimisticResults = 'optimistic' regardless of subscribed. React handles this (#10759), as does preact's useQueries (#11130) and this PR applies the same fix to preact's useBaseQuery, with the test ported from #10759

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes

    • Queries configured without subscriptions no longer enter an optimistic fetching state.
    • Unsubscribed queries remain idle and do not trigger fetching.
    • Existing subscribed query behavior remains unchanged.
  • Tests

    • Added coverage for unsubscribed queries after initial fetching and queries initialized with subscriptions disabled.

@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: a2581b58-196e-4842-ade4-23690675a0db

📥 Commits

Reviewing files that changed from the base of the PR and between 66d4fe3 and 29bcca3.

📒 Files selected for processing (3)
  • .changeset/preact-unsubscribed-optimistic-state.md
  • packages/preact-query/src/__tests__/unsubscribed-optimistic.test.tsx
  • packages/preact-query/src/useBaseQuery.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The Preact useQuery hook now avoids optimistic fetching and observer subscriptions when subscribed: false. Tests cover both initial and subsequent unsubscribe states, and a patch changeset documents the fix.

Changes

Preact unsubscribed query handling

Layer / File(s) Summary
Subscription gating and validation
packages/preact-query/src/useBaseQuery.ts, packages/preact-query/src/__tests__/unsubscribed-optimistic.test.tsx, .changeset/preact-unsubscribed-optimistic-state.md
useBaseQuery disables optimistic results and observer subscriptions when subscribed is false. Tests verify idle state and no query-function call. A patch changeset documents the change.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: tkdodo

Merge Risk: ⚪ Minimal · up to 29bcc

The change confines unsubscribed Preact queries to an idle, non-fetching state and includes coverage for initial and rerendered unsubscribed cases. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preventing optimistic fetching state when preact-query is not subscribed.
Description check ✅ Passed The description includes all required sections, explains the problem and fix, marks the checklist items complete, and confirms the changeset for published code.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant