Skip to content

fix(query-codemods): forward extra args in keep-previous-data#11039

Open
KangaZero wants to merge 1 commit into
TanStack:mainfrom
KangaZero:fix-keep-previous-data-slice
Open

fix(query-codemods): forward extra args in keep-previous-data#11039
KangaZero wants to merge 1 commit into
TanStack:mainfrom
KangaZero:fix-keep-previous-data-slice

Conversation

@KangaZero

@KangaZero KangaZero commented Jul 9, 2026

Copy link
Copy Markdown

🎯 Changes

In the keep-previous-data codemod, the QueryClient-method transformer rebuilds the call expression as [arg0, transformedArg1, ...node.arguments.slice(2, 0)]. The intent of the spread is to forward any arguments beyond the second, but slice(2, 0) always returns [] — per the spec, when end < start the result is empty. So the spread is a no-op that silently discards any trailing arguments.

The fix drops the erroneous end argument so the tail is actually forwarded:

-          ...node.arguments.slice(2, 0),
+          ...node.arguments.slice(2),

This matches the ...slice(2) form already used in the remove-overloads transformer.

Scope note: today this codemod only transforms setQueryDefaults, whose public signature is 2-arg (queryKey, options), so no current input reaches a 3rd argument — this is a correctness/robustness fix that removes a dead-code no-op and guards the transformer against future config additions or hand-written input, rather than a fix for an observed broken migration.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with the package's test suite (@tanstack/query-codemods vitest + eslint pass).

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release) — @tanstack/query-codemods is a private, unpublished package, so no changeset applies.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where an update path could drop extra arguments in certain query-related transformations, preserving the full original call details.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

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

Run ID: bf0e2580-d531-4e72-8f6c-c10bfedec6d6

📥 Commits

Reviewing files that changed from the base of the PR and between 64241b8 and b3d5637.

📒 Files selected for processing (1)
  • packages/query-codemods/src/v5/keep-previous-data/keep-previous-data.cjs

📝 Walkthrough

Walkthrough

Fixed a bug in the keep-previous-data codemod's transformNode function where node.arguments.slice(2, 0) incorrectly returned an empty array, dropping trailing arguments beyond the first two. Changed to node.arguments.slice(2) to correctly preserve those arguments.

Changes

Codemod Argument Fix

Layer / File(s) Summary
Fix argument slicing in transformNode
packages/query-codemods/src/v5/keep-previous-data/keep-previous-data.cjs
Corrected the slice call from node.arguments.slice(2, 0) to node.arguments.slice(2) so trailing arguments beyond the first two are preserved instead of dropped.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the codemod fix to forward extra arguments.
Description check ✅ Passed The description matches the template and includes the changes, checklist, and release impact sections with relevant details.
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

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