GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(query-core): Keep observer notifications stable by scttcper · Pull Request #11234 · TanStack/query

Conversation

@scttcper

@scttcper scttcper commented Aug 20, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

PR #11214 changed observer removal from filter() to splice(). That made removing lots of observers much faster, but it also allowed an observer to change the same array while a query was notifying it. If an observer unsubscribed synchronously, the next observer could be skipped and left with stale data.

This notifies a shallow copy of the observer array. The removal path still uses splice(), so the performance improvement from #11214 stays.

I ran a local Vitest benchmark that calls setQueryData on one query with all observers subscribed:

Observers Before After
10 0.0027 ms 0.0027 ms
50 0.0096 ms 0.0101 ms
10,000 2.6049 ms 2.6032 ms

There isn't a meaningful change in notification time. The key change and unmount paths measured in #11214 are unchanged because this does not change observer removal.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed query updates so all remaining observers are notified correctly when another observer unsubscribes during notification.
    • Ensured observers receive the latest query data consistently during synchronous updates.
  • Tests

    • Added regression coverage for observer notifications during unsubscribe scenarios.
  • Release

    • Included in a patch release of @tanstack/query-core.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@scttcper @codex
fix(query-core): Keep observer notifications stable
131504a
Removing an observer in place can shift the active notification loop and skip the next observer. Iterate over a shallow copy so synchronous unsubscriptions keep the old behavior without giving up the faster removal path from TanStack#11214.

Co-Authored-By: Codex <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 20, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b133350a-a59a-4e5c-a4be-d39fc870d97e

📥 Commits

Reviewing files that changed from the base of the PR and between 64a8035 and 131504a.

📒 Files selected for processing (3)
  • .changeset/stable-observers-notify.md
  • packages/query-core/src/__tests__/query.test.tsx
  • packages/query-core/src/query.ts

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


📝 Walkthrough

Walkthrough

The query dispatch path now snapshots observers before notification. A regression test verifies that remaining observers receive updated data after one observer unsubscribes synchronously. A patch changeset documents the fix.

Changes

Observer notification stability

Layer / File(s) Summary
Stable dispatch and regression coverage
packages/query-core/src/query.ts, packages/query-core/src/__tests__/query.test.tsx, .changeset/stable-observers-notify.md
Query.#dispatch iterates over a snapshot of observers. The regression test verifies notification of the remaining observer after synchronous unsubscription. The changeset declares a patch release.
Estimated code review effort: 2 (Simple) ~10 minutes

Merge Risk: ⚪ Minimal · up to 13150

This localized change stabilizes observer notifications while preserving the existing removal performance improvement, and no actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

  • TanStack/query#11231: This PR applies the same observer snapshot fix and regression coverage.
  • TanStack/query#11214: Both PRs change observer-array handling in packages/query-core/src/query.ts.

Suggested reviewers: tkdodo

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: stabilizing query observer notifications during synchronous unsubscription.
Description check ✅ Passed The description explains the bug, fix, performance impact, and benchmark results, but it omits the template checklist and release-impact headings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@scttcper
scttcper marked this pull request as ready for review August 20, 2026 00:38
@TkDodo TkDodo mentioned this pull request Aug 20, 2026
fix(query-core): notify sibling observers when one unsubscribes during dispatch #11231
Closed
TkDodo
TkDodo approved these changes Aug 20, 2026
View reviewed changes
@nx-cloud

nx-cloud Bot commented Aug 20, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 131504a

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

☁️ Nx Cloud last updated this comment at 2026-08-20 08:07:42 UTC

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pkg-pr-new

pkg-pr-new Bot commented Aug 20, 2026

Copy link
Copy Markdown
More templates

  • @tanstack/query-example-angular-auto-refetching
  • @tanstack/query-example-angular-basic
  • @tanstack/query-example-angular-basic-persister
  • @tanstack/query-example-angular-devtools-panel
  • @tanstack/query-example-angular-infinite-query-with-max-pages
  • @tanstack/query-example-angular-optimistic-updates
  • @tanstack/query-example-angular-pagination
  • @tanstack/query-example-angular-query-options-from-a-service
  • @tanstack/query-example-angular-router
  • @tanstack/query-example-angular-rxjs
  • @tanstack/query-example-angular-simple
  • @tanstack/query-example-lit-basic
  • @tanstack/query-example-lit-pagination
  • @tanstack/query-example-lit-ssr
  • @tanstack/query-example-preact-simple
  • @tanstack/query-example-react-algolia
  • @tanstack/query-example-react-auto-refetching
  • @tanstack/query-example-react-basic
  • @tanstack/query-example-react-basic-graphql-request
  • @tanstack/query-example-chat
  • @tanstack/query-example-react-default-query-function
  • @tanstack/query-example-react-devtools-panel
  • @tanstack/query-example-eslint-legacy
  • @tanstack/query-example-eslint-plugin-demo
  • @tanstack/query-example-react-infinite-query-with-max-pages
  • @tanstack/query-example-react-load-more-infinite-scroll
  • @tanstack/query-example-react-nextjs
  • @tanstack/query-example-react-nextjs-app-optimistic-updates
  • @tanstack/query-example-react-nextjs-app-prefetching
  • @tanstack/query-example-nextjs-suspense-streaming
  • @tanstack/query-example-react-offline
  • @tanstack/query-example-react-pagination
  • @tanstack/query-example-react-playground
  • @tanstack/query-example-react-prefetching
  • @tanstack/query-example-react-react-native
  • @tanstack/query-example-react-router
  • @tanstack/query-example-react-rick-morty
  • @tanstack/query-example-react-shadow-dom
  • @tanstack/query-example-react-simple
  • @tanstack/query-example-react-star-wars
  • @tanstack/query-example-react-suspense
  • @tanstack/query-example-solid-astro
  • @tanstack/query-example-solid-basic
  • @tanstack/query-example-solid-basic-graphql-request
  • @tanstack/query-example-solid-default-query-function
  • @tanstack/query-example-solid-offline
  • @tanstack/query-example-solid-simple
  • @tanstack/query-example-solid-start-streaming
  • @tanstack/query-example-svelte-auto-refetching
  • @tanstack/query-example-svelte-basic
  • @tanstack/query-example-svelte-load-more-infinite-scroll
  • @tanstack/query-example-svelte-optimistic-updates
  • @tanstack/query-example-svelte-playground
  • @tanstack/query-example-svelte-simple
  • @tanstack/query-example-svelte-ssr
  • @tanstack/query-example-svelte-star-wars
  • @tanstack/query-example-vue-2.6-basic
  • @tanstack/query-example-vue-2.7-basic
  • @tanstack/query-example-vue-basic
  • @tanstack/query-example-vue-dependent-queries
  • @tanstack/query-example-vue-nuxt3
  • @tanstack/query-example-vue-persister
  • @tanstack/query-example-vue-simple

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@11234

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@11234

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@11234

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 131504a

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TkDodo
TkDodo merged commit 9656dc4 into TanStack:main Aug 20, 2026
9 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Aug 20, 2026
ci: Version Packages #11206
Merged
@haowjy haowjy mentioned this pull request Nov 16, 2026
Move the app and server libraries to current versions haowjy/meridian-flow#1651
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@TkDodo TkDodo TkDodo approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@scttcper @TkDodo
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.