feat(tanstack-query): support defaults factory - #1570
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR extends the TanStack Query integration to support function-based ChangesFunction-based experimental_defaults
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a function form for experimental_defaults in createRouterUtils, allowing default configurations to dynamically reference generated query or mutation keys without self-reference issues. It updates the documentation to explain this new capability, adds corresponding type and unit tests, and refactors createRouterUtils to evaluate the defaults factory function when provided. There are no review comments, and I have no feedback to provide.
|
Actionable comments posted: 0 |
There was a problem hiding this comment.
Reviewed changes — Adds a factory-function form for experimental_defaults in createTanstackQueryUtils, allowing cache-invalidation patterns that reference generated keys without a self-referencing outer variable. The object form remains fully supported and defaults still shallow-merge as before.
experimental_RouterUtilsDefaultsOption<T>— new union type exported fromrouter-utils.ts.createRouterUtilsruntime — resolves factory once at top level, then passes the resolved defaults object intocreateProcedureUtilsand into recursive child calls.- Tests — runtime test verifies the factory is called once and defaults propagate; type test verifies typed access to utils inside the factory.
- Docs — updated TanStack Query docs page with function-form example and a note about shallow-merge override behavior.
Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:
packages/tanstack-query/src/index.ts:4(RIGHT) — file not in PR diff
Kimi K2 | 𝕏
There was a problem hiding this comment.
Reviewed changes — Adds a factory-function form for experimental_defaults in createTanstackQueryUtils, allowing cache-invalidation patterns that reference generated keys without a self-referencing outer variable. The object form remains fully supported and defaults still shallow-merge as before.
experimental_RouterUtilsDefaultsOption<T>— new union type exported fromrouter-utils.ts.createRouterUtilsruntime — resolves factory once at top level, then passes the resolved defaults object intocreateProcedureUtilsand into recursive child calls.- Tests — runtime test verifies the factory is called once and defaults propagate; type test verifies typed access to utils inside the factory.
- Docs — updated TanStack Query docs page with function-form example and a note about shallow-merge override behavior.
Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:
packages/tanstack-query/src/index.ts:4(RIGHT) — file not in PR diff
Kimi K2 | 𝕏

Fixes #1569.
This lets
experimental_defaultstake a function in addition to the existing object form:The goal is to keep procedure-level server-state defaults close to the router while avoiding a self-reference to the outer
orpcvariable. The object form keeps working, and defaults still use the existing shallow merge behavior.Summary by CodeRabbit
New Features
Documentation