Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

TkDodo
Copy link
Collaborator

@TkDodo TkDodo commented Sep 1, 2025

this avoids the weirdly double-nested queryFn naming

Summary by CodeRabbit

  • Refactor

    • Renamed the streamedQuery public option from "queryFn" to "streamFn". Behavior and streaming semantics are unchanged; update integrations to use "streamFn".
  • Documentation

    • Updated streaming API docs and examples to use "streamFn" and reworded the option description; minor formatting fix.
  • Tests

    • Updated streamedQuery tests to use the new "streamFn" option name.
  • Examples

    • Updated example usage to pass the streaming function via "streamFn".

this avoids the weirdly double-nested queryFn naming
Copy link
Contributor

coderabbitai bot commented Sep 1, 2025

Walkthrough

Renames the public streaming option from queryFn to streamFn across implementation, tests, docs, and an example; behavior, control flow, and return types are unchanged.

Changes

Cohort / File(s) Summary
Core implementation & types
packages/query-core/src/streamedQuery.ts
Renamed public option/type property queryFnstreamFn; destructures streamFn and calls streamFn(context) internally. No change to streaming semantics.
Tests
packages/query-core/src/__tests__/streamedQuery.test.tsx
Updated tests to use streamFn instead of queryFn; test logic and assertions unchanged.
Docs
docs/reference/streamedQuery.md
Updated API docs and example to show streamFn option and adjusted option signature/description text and minor formatting.
Example
examples/react/chat/src/chat.ts
Replaced queryFnstreamFn in chatQueryOptions; implementation unchanged.

Sequence Diagram(s)

(Skipped — changes are a public option rename only; control flow is unchanged.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

I twitch my ears at streams anew,
A tiny name change — nothing askew.
From queryFn to streamFn I sing,
Same flow, same hops, a joyful spring.
I nibble code and bound away — the stream still dances bright as day. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/streamFn

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

nx-cloud bot commented Sep 1, 2025

View your CI Pipeline Execution ↗ for commit dd12c6c

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 3m 10s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 20s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-04 09:12:04 UTC

Copy link

pkg-pr-new bot commented Sep 1, 2025

More templates

@tanstack/angular-query-devtools-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-devtools-experimental@9606

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@9606

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@9606

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@9606

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@9606

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@9606

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@9606

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@9606

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@9606

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@9606

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@9606

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@9606

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@9606

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@9606

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@9606

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@9606

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@9606

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@9606

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@9606

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@9606

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@9606

commit: dd12c6c

Copy link

github-actions bot commented Sep 1, 2025

Sizes for commit dd12c6c:

Branch Bundle Size
Main
This PR

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/query-core/src/streamedQuery.ts (1)

9-9: Fix JSDoc: @param name still says queryFn.

Update the param tag to match the new API.

- * @param queryFn - The function that returns an AsyncIterable to stream data from.
+ * @param streamFn - The function that returns an AsyncIterable to stream data from.
🧹 Nitpick comments (1)
packages/query-core/src/__tests__/streamedQuery.test.tsx (1)

519-519: Add a small coverage boost: streamFn returning a Promise.

Your types allow Promise; add a test to lock this in.

+++ a/packages/query-core/src/__tests__/streamedQuery.test.tsx
@@
 describe('streamedQuery', () => {
+  test('should accept streamFn that returns a Promise<AsyncIterable>', async () => {
+    const key = queryKey()
+    const observer = new QueryObserver(queryClient, {
+      queryKey: key,
+      queryFn: streamedQuery({
+        streamFn: async () => Promise.resolve(createAsyncNumberGenerator(2)),
+      }),
+    })
+    const unsubscribe = observer.subscribe(vi.fn())
+    await vi.advanceTimersByTimeAsync(100)
+    expect(observer.getCurrentResult()).toMatchObject({
+      status: 'success',
+      fetchStatus: 'idle',
+      data: [0, 1],
+    })
+    unsubscribe()
+  })
 })
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0650eaf and 98b68c2.

📒 Files selected for processing (2)
  • packages/query-core/src/__tests__/streamedQuery.test.tsx (9 hunks)
  • packages/query-core/src/streamedQuery.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Preview
  • GitHub Check: Test
🔇 Additional comments (2)
packages/query-core/src/streamedQuery.ts (1)

23-23: API rename verified — no remaining queryFn usage; callers must switch to streamFn. Breaking change—update release notes/changelog accordingly.

packages/query-core/src/__tests__/streamedQuery.test.tsx (1)

37-37: Tests updated to use streamFn: consistent and correct.

All call sites now pass streamFn to streamedQuery while keeping QueryObserver’s queryFn as-is. Semantics preserved.

Also applies to: 81-81, 136-136, 190-192, 246-248, 303-305, 358-364, 399-401, 444-447

Copy link

codecov bot commented Sep 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.37%. Comparing base (43049c5) to head (dd12c6c).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9606       +/-   ##
===========================================
+ Coverage   45.26%   59.37%   +14.10%     
===========================================
  Files         208      137       -71     
  Lines        8340     5580     -2760     
  Branches     1894     1510      -384     
===========================================
- Hits         3775     3313      -462     
+ Misses       4118     1963     -2155     
+ Partials      447      304      -143     
Components Coverage Δ
@tanstack/angular-query-devtools-experimental ∅ <ø> (∅)
@tanstack/angular-query-experimental 87.00% <ø> (ø)
@tanstack/eslint-plugin-query ∅ <ø> (∅)
@tanstack/query-async-storage-persister 43.85% <ø> (ø)
@tanstack/query-broadcast-client-experimental 24.39% <ø> (ø)
@tanstack/query-codemods ∅ <ø> (∅)
@tanstack/query-core 97.43% <100.00%> (+<0.01%) ⬆️
@tanstack/query-devtools 3.48% <ø> (ø)
@tanstack/query-persist-client-core 79.47% <ø> (ø)
@tanstack/query-sync-storage-persister 84.61% <ø> (ø)
@tanstack/query-test-utils ∅ <ø> (∅)
@tanstack/react-query 96.00% <ø> (ø)
@tanstack/react-query-devtools 10.00% <ø> (ø)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client 100.00% <ø> (ø)
@tanstack/solid-query 78.13% <ø> (ø)
@tanstack/solid-query-devtools ∅ <ø> (∅)
@tanstack/solid-query-persist-client 100.00% <ø> (ø)
@tanstack/svelte-query 87.58% <ø> (ø)
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client 100.00% <ø> (ø)
@tanstack/vue-query 71.10% <ø> (ø)
@tanstack/vue-query-devtools ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Sep 3, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
examples/react/chat/src/chat.ts (1)

11-24: Optional: honor AbortSignal to avoid running timers after abort/unmount.
Hook into the QueryFunctionContext’s signal so the generator exits early and avoids dangling timeouts.

Apply within the current diff hunk:

-      streamFn: () => chatAnswer(question),
+      streamFn: (ctx) => chatAnswer(question, ctx.signal),

Then adjust the helper (outside this hunk):

function chatAnswer(_question: string, signal?: AbortSignal) {
  return {
    async *[Symbol.asyncIterator]() {
      const answer = answers[Math.floor(Math.random() * answers.length)]
      let index = 0
      while (index < answer.length) {
        // bail out early on abort
        if (signal?.aborted) return
        await new Promise((resolve) => setTimeout(resolve, 100 + Math.random() * 300))
        if (signal?.aborted) return
        yield answer[index++]
      }
    },
  }
}
docs/reference/streamedQuery.md (1)

25-27: Tighten wording for streamFn description.
Minor grammar/style tweak.

-- `streamFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TData>>`
   - **Required**
-  - The function that returns a Promise of an AsyncIterable with data to stream in.
+  - A function that returns a Promise that resolves to an AsyncIterable of chunks to stream.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 98b68c2 and 23c99d1.

📒 Files selected for processing (2)
  • docs/reference/streamedQuery.md (2 hunks)
  • examples/react/chat/src/chat.ts (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/reference/streamedQuery.md

[grammar] ~27-~27: There might be a mistake here.
Context: ...an AsyncIterable with data to stream in. - Receives a [QueryFunctionContext](../../...

(QB_NEW_EN)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Preview
  • GitHub Check: Test
🔇 Additional comments (2)
examples/react/chat/src/chat.ts (1)

29-31: Rename wired correctly — streamFn is passed to streamedQuery as intended.

docs/reference/streamedQuery.md (1)

15-17: Example updated correctly to streamFn.
Matches the new API surface.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
docs/reference/streamedQuery.md (1)

29-29: Resolved: closing quote added to refetchMode union.

The unterminated string literal is fixed.

🧹 Nitpick comments (2)
docs/reference/streamedQuery.md (2)

27-27: Tighten wording for clarity (LT flagged).

Current phrasing is a bit clunky; suggest:

-  - The function that returns a Promise of an AsyncIterable with data to stream in.
+  - Returns a Promise that resolves to an AsyncIterable of chunks to stream.

41-45: Clarify initialValue line to avoid implying invalid TS syntax and conflicting defaults.

As written, initialValue?: TData = TQueryFnData reads like a type default and also conflicts with “Defaults to an empty array.” Recommend splitting semantics and stating the default plainly.

- - `initialValue?: TData = TQueryFnData`
+ - `initialValue?: TData`
   - Optional
-  - Defines the initial data to be used while the first chunk is being fetched.
+  - Defines the initial data to use while the first chunk is being fetched.
   - It is mandatory when custom `reducer` is provided.
-  - Defaults to an empty array.
+  - Default: an empty array (unless specified).
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 23c99d1 and dd12c6c.

📒 Files selected for processing (3)
  • docs/reference/streamedQuery.md (2 hunks)
  • packages/query-core/src/__tests__/streamedQuery.test.tsx (9 hunks)
  • packages/query-core/src/streamedQuery.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/query-core/src/streamedQuery.ts
  • packages/query-core/src/tests/streamedQuery.test.tsx
🧰 Additional context used
🪛 LanguageTool
docs/reference/streamedQuery.md

[grammar] ~27-~27: There might be a mistake here.
Context: ...an AsyncIterable with data to stream in. - Receives a [QueryFunctionContext](../../...

(QB_NEW_EN)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test
🔇 Additional comments (1)
docs/reference/streamedQuery.md (1)

16-16: Example updated to streamFn — looks correct.

The rename in the usage snippet is consistent and accurate.

**Options**

- `queryFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TData>>`
- `streamFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TData>>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Type parameter mismatch: streamFn should yield TQueryFnData, not TData.

This conflicts with the reducer signature using TQueryFnData for chunks.

Apply this diff:

- - `streamFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TData>>`
+ - `streamFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TQueryFnData>>`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- `streamFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TData>>`
- `streamFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TQueryFnData>>`
🤖 Prompt for AI Agents
In docs/reference/streamedQuery.md around line 25, the documented type for
streamFn uses TData but it should yield TQueryFnData to match the reducer
signature; update the signature from `streamFn: (context: QueryFunctionContext)
=> Promise<AsyncIterable<TData>>` to `streamFn: (context: QueryFunctionContext)
=> Promise<AsyncIterable<TQueryFnData>>` (or the equivalent doc representation)
so the type parameter for streamed chunks aligns with the reducer's
TQueryFnData.

@TkDodo TkDodo merged commit b25412a into main Sep 4, 2025
8 checks passed
@TkDodo TkDodo deleted the feature/streamFn branch September 4, 2025 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation package: query-core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants