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

Skip to content

Conversation

Sc4ramouche
Copy link
Contributor

@Sc4ramouche Sc4ramouche commented Aug 26, 2025

The API page for cancelQueries does not mention that it accepts second optional parameter of CancelOptions (docs page), which is indicated by the TypeScript signature.

  • Added Cancel Options section to the Filters guide. Not sure if this is the optimal location for them though, please advise if there's more fitting place.
  • Added mention of cancelOptions for cancelQueries call.

Summary by CodeRabbit

  • New Features

    • Added optional cancellation options and two-argument form for query cancellation, enabling configurable behavior (silent, revert).
  • Documentation

    • Added Cancel Options docs and examples showing usage with silent/revert.
    • Clarified behavior: silent suppresses error propagation and returns retry promise; revert restores previous state and resets fetch status, throwing only when no prior data exists.

Copy link
Contributor

coderabbitai bot commented Aug 26, 2025

Walkthrough

Documentation updates add a second optional parameter cancelOptions?: CancelOptions to QueryClient.cancelQueries, introduce a Cancel Options section explaining silent and revert, update examples to the two-argument form, and link reference and guide pages accordingly.

Changes

Cohort / File(s) Summary
Reference: QueryClient API
docs/reference/QueryClient.md
Updated cancelQueries signature to accept optional second parameter cancelOptions?: CancelOptions; adjusted example to two-argument form; added link to Cancel Options documentation.
React Guide: Query Cancellation
docs/framework/react/guides/query-cancellation.md
Added Cancel Options section defining CancelOptions properties (silent, revert), defaults and behavior, and example usage queryClient.cancelQueries({ queryKey: ['posts'] }, { silent: true }).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as Caller
  participant QC as QueryClient
  participant Q as Matching Queries

  U->>QC: cancelQueries(filters, cancelOptions?)
  Note right of QC: cancelOptions: { silent?, revert? }

  QC->>Q: Locate queries matching filters
  alt revert = true
    QC->>Q: Revert to previous state\n(restore data, set fetchStatus=idle)
  else revert = false
    QC->>Q: Leave current state unchanged
  end

  alt silent = true
    Note over QC,U: Suppress CancelledError propagation
    QC-->>U: Return retry promise (no throw)
  else silent = false
    QC-->>U: Propagate CancelledError on cancellation
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my ears at queries’ pleas,
With cancelOptions, I appease—
Silent hops, no errors tossed,
Or backwards tracks when state is lost.
Two-arg dance, a tidy art,
Docs now chart the rabbit’s heart. 🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 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.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Aug 26, 2025
@Sc4ramouche Sc4ramouche marked this pull request as ready for review August 26, 2025 13:01
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

🧹 Nitpick comments (5)
docs/reference/QueryClient.md (1)

405-416: Add cancelOptions parameter in example and specify return type for cancelQueries

To align the docs with the core API signature and other async methods, include the second cancelOptions argument in the usage example and update the Returns section to reflect that it returns a Promise<void>.

• File: docs/reference/QueryClient.md
• Lines: 405–416

```tsx
-await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })
+await queryClient.cancelQueries(
+  { queryKey: ['posts'], exact: true },
+  { silent: true }
+)

Options

Returns

  • Promise<void>
    • Resolves once cancellation has been attempted for all matching queries.

</blockquote></details>
<details>
<summary>docs/framework/react/guides/filters.md (4)</summary><blockquote>

`74-76`: **Section placement reads well; consider surfacing “Cancel Options” more broadly.**

This topic applies to query cancellation (and potentially mutation cancellation in other areas), not just filters. Optional: Promote “Cancel Options” to its own top-level guide (or a shared “Options”/“Cancellations” page) and link to it from both this page and the QueryClient reference, improving discoverability from the sidebar.

---

`79-84`: **Enrich the example to demonstrate both options and the practical effect.**

Showing only `silent: true` is correct but minimal. Add `revert: false` to illustrate behavior differences during an in-flight refetch.


Apply this diff to extend the snippet:

```diff
 ```tsx
-// Cancel specific queries silently
-await queryClient.cancelQueries(
-  { queryKey: ['posts'] },
-  { silent: true }
-)
+// Cancel specific queries:
+// - silent: don't propagate a CancelledError to observers
+// - revert: keep the current state instead of reverting to the previous one
+await queryClient.cancelQueries(
+  { queryKey: ['posts'] },
+  { silent: true, revert: false }
+)

---

`86-94`: **Consider adding a TypeScript shape alongside the prose.**

A compact TS snippet improves scanability and aligns with other sections.


Add this block just above the options list:

```ts
type CancelOptions = {
  silent?: boolean // default: false
  revert?: boolean // default: true
}

88-94: Refine silent and revert documentation to match actual behavior

Replace the existing snippet with the following for greater accuracy:

- `silent?: boolean`
-  - When set to `true`, prevents `CancelledError` from being thrown during query cancellation.
-  - Defaults to `false`
+ `silent?: boolean`
+  - When set to `true`, suppresses propagation of `CancelledError` to observers (e.g., `onError` callbacks) and related notifications, and returns the retry promise instead of rejecting.
+  - Defaults to `false`

- `revert?: boolean`
-  - When set to `true`, reverts the query to its previous state before cancellation.
-  - Defaults to `true`
+ `revert?: boolean`
+  - When set to `true`, restores the query’s state (data and status) from immediately before the in-flight fetch, sets `fetchStatus` back to `idle`, and only throws if there was no prior data.
+  - Defaults to `true`
📜 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 a1b1279 and d3bbe4f.

📒 Files selected for processing (2)
  • docs/framework/react/guides/filters.md (1 hunks)
  • docs/reference/QueryClient.md (1 hunks)

Copy link

nx-cloud bot commented Aug 30, 2025

View your CI Pipeline Execution ↗ for commit b913dbe

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

☁️ Nx Cloud last updated this comment at 2025-09-02 02:38:39 UTC

Copy link

pkg-pr-new bot commented Aug 30, 2025

More templates

@tanstack/angular-query-devtools-experimental

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

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: b913dbe

**Options**

- `filters?: QueryFilters`: [Query Filters](../../framework/react/guides/filters.md#query-filters)
- `cancelOptions?: CancelOptions`: [Cancel Options](../../framework/react/guides/filters.md#cancel-options)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- `cancelOptions?: CancelOptions`: [Cancel Options](../../framework/react/guides/filters.md#cancel-options)
- `cancelOptions?: CancelOptions`: [Cancel Options](../../framework/react/guides/query-cancellation#XXX)

I think this would be a better place for CancelOptions. because CancelOptions is not about filters

Copy link
Contributor Author

@Sc4ramouche Sc4ramouche Sep 1, 2025

Choose a reason for hiding this comment

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

Thanks, moved it to query-cancellation guide.

@Sc4ramouche Sc4ramouche requested a review from manudeli September 1, 2025 12:37
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

🧹 Nitpick comments (2)
docs/framework/react/guides/query-cancellation.md (1)

191-208: Clarify CancelOptions semantics and avoid implementation-leaky phrasing.

  • “returns the retry promise instead of rejecting” is internal-detail-y and may confuse readers. Prefer describing outward effects (no observer error notifications) over return mechanics.
  • Defaults for silent/revert appear to vary by call site (e.g., internal cancels often use silent: true; unmount cancels use revert: true). Please avoid stating global defaults unless guaranteed by the public API; otherwise, add a short note that defaults are contextual. Evidence from maintainers/issues shows CancelledError carries { silent, revert } flags and is often silent, not noisy. (github.com)

Apply:

-  - When set to `true`, suppresses propagation of `CancelledError` to observers (e.g., `onError` callbacks) and related notifications, and returns the retry promise instead of rejecting.
-  - Defaults to `false`
+  - When set to `true`, suppresses propagation of `CancelledError` to observers (e.g., `onError` callbacks) and related notifications.
+  - Note: In practice, many internal cancellations are silent by default; behavior can be contextual.
@@
-  - When set to `true`, restores the query’s state (data and status) from immediately before the in-flight fetch, sets `fetchStatus` back to `idle`, and only throws if there was no prior data.
-  - Defaults to `true`
+  - When set to `true`, restores the query’s state (data and status) from immediately before the in-flight fetch and sets `fetchStatus` back to `idle`.
+  - Note: Revert is commonly used for unmount/abort flows.
+  
+```ts
+// Type shape for reference
+type CancelOptions = {
+  silent?: boolean
+  revert?: boolean
+}
+```

Please confirm with maintainers whether global defaults should be documented. If yes, I’ll update the copy accordingly.

docs/reference/QueryClient.md (1)

414-416: Tiny formatting/grammar tweak for Options list.

Insert a blank line between bullets to silence some linters and improve readability; keep consistent with other sections.

 **Options**
 
-- `filters?: QueryFilters`: [Query Filters](../../framework/react/guides/filters.md#query-filters)
-`cancelOptions?: CancelOptions`: [Cancel Options](../../framework/react/guides/query-cancellation.md#cancel-options)
+- `filters?: QueryFilters`: [Query Filters](../../framework/react/guides/filters.md#query-filters)
+
+- `cancelOptions?: CancelOptions`: [Cancel Options](../../framework/react/guides/query-cancellation.md#cancel-options)

Also verify the anchor slug resolves correctly given the header is written as “## Cancel Options” (Docusaurus usually slugifies this to #cancel-options). Build preview to be safe.

📜 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 cc1d561 and b6921d8.

📒 Files selected for processing (2)
  • docs/framework/react/guides/query-cancellation.md (1 hunks)
  • docs/reference/QueryClient.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/reference/QueryClient.md

[grammar] ~414-~414: There might be a mistake here.
Context: ...filters?: QueryFilters: Query Filters - cancelOptions?: CancelOptions: [Cancel Options](../../framework/react...

(QB_NEW_EN)

🪛 markdownlint-cli2 (0.17.2)
docs/reference/QueryClient.md

412-412: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🔇 Additional comments (1)
docs/reference/QueryClient.md (1)

406-409: Sample update looks good.

Two-argument example for cancelQueries is clear and consistent with the intended signature. ✔️

Copy link
Collaborator

@manudeli manudeli left a comment

Choose a reason for hiding this comment

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

Thank you for reflecting my review

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

🧹 Nitpick comments (1)
docs/reference/QueryClient.md (1)

406-409: Example looks good; align the Returns section with async usage

You’re using await here, so please document that cancelQueries returns Promise<void> instead of “does not return anything.”

Apply this diff to the Returns subsection below:

-**Returns**
-
-This method does not return anything
+**Returns**
+
+- `Promise<void>`
+  - Resolves when matching queries have been cancelled.
📜 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 b6921d8 and b913dbe.

📒 Files selected for processing (1)
  • docs/reference/QueryClient.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/reference/QueryClient.md

[grammar] ~414-~414: There might be a mistake here.
Context: ...filters?: QueryFilters: Query Filters - cancelOptions?: CancelOptions: [Cancel Options](../../framework/react...

(QB_NEW_EN)

🪛 markdownlint-cli2 (0.17.2)
docs/reference/QueryClient.md

412-412: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🔇 Additional comments (2)
docs/reference/QueryClient.md (2)

412-412: Ignore MD036 here (repo-wide pattern)

“Options” is consistently styled as bold text across this page; keep as-is despite markdownlint’s MD036 warning.


415-415: The requested script is running; I’ll revisit once we have its output.

@manudeli manudeli merged commit f97d725 into TanStack:main Sep 2, 2025
6 checks passed
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants