Skip to content

fix(query-core): reject longer partial array keys - #11502

Merged
TkDodo merged 2 commits into
TanStack:mainfrom
gwagjiug:fix/partial-match-key-array-length
Sep 15, 2026
Merged

TkDodo merged 2 commits into
TanStack:mainfrom
gwagjiug:fix/partial-match-key-array-length

Conversation

@gwagjiug

@gwagjiug gwagjiug commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

partialMatchKey previously iterated over every element in the filter key without first checking whether the candidate array was long enough. A filter such as ['todos', undefined] therefore matched the shorter ['todos'] key because both missing and explicit array elements evaluate to undefined.

  • Return false when an array filter is longer than the candidate array.
  • Add a regression test for a trailing undefined filter element.
  • Add a patch changeset for @tanstack/query-core.

Validation: pnpm run test:pr with Node 24.16.0.

✅ 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

    • Fixed partial query-key matching so longer filters with trailing undefined values no longer match shorter query keys.
    • Improved query matching accuracy when the filter contains more array elements than the target key.
    • Prevented incorrect matches caused by differences in query-key length.
  • Tests

    • Added coverage for preventing incorrect matches between query keys of different lengths, including keys with trailing undefined values.

@coderabbitai

coderabbitai Bot commented Sep 15, 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: 63ea559a-2d12-4e8c-921c-192b45e0c970

📥 Commits

Reviewing files that changed from the base of the PR and between e8f8da5 and 28ad044.

📒 Files selected for processing (1)
  • packages/query-core/src/__tests__/utils.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/query-core/src/tests/utils.test.tsx

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


📝 Walkthrough

Walkthrough

The change updates partialMatchKey to reject longer array filters, adds a regression test for trailing undefined values, and records a patch release for @tanstack/query-core.

Changes

Partial query-key matching

Layer / File(s) Summary
Array length guard and regression coverage
packages/query-core/src/utils.ts, packages/query-core/src/__tests__/utils.test.tsx, .changeset/short-arrays-match.md
partialMatchKey now returns false when array b is longer than array a. A test covers [1] and [1, undefined]. The changeset declares a patch release.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: sheraz4196

Merge Risk: ⚪ Minimal · up to 28ad0

The array-filter behavior is corrected and covered by a focused regression test; 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 1 functions across 2 files. 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 primary change: rejecting longer partial array keys in query-core.
Description check ✅ Passed The description follows the required template, explains the fix and motivation, documents the regression test and validation command, and marks the checklist and release impact accurately.
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.
  • Fix all pre-merge checks with AI
✨ 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

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

@gwagjiug gwagjiug changed the title fix(query-core): reject longer partial array keys 🤖🤖🤖 fix(query-core): reject longer partial array keys Sep 15, 2026
@nx-cloud

nx-cloud Bot commented Sep 15, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit e8f8da5

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 20s View ↗

☁️ Nx Cloud last updated this comment at 2026-09-15 16:37:09 UTC

@pkg-pr-new

pkg-pr-new Bot commented Sep 15, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: e8f8da5

Comment thread packages/query-core/src/__tests__/utils.test.tsx Outdated
@TkDodo
TkDodo merged commit cbf77bf into TanStack:main Sep 15, 2026
3 checks passed
@github-actions github-actions Bot mentioned this pull request Sep 15, 2026
@gwagjiug
gwagjiug deleted the fix/partial-match-key-array-length branch September 16, 2026 09:07
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.

3 participants