[WIP] Angular injectQueries fixes #8690
main fromrefs/pull/8690/head·merged by arnoud-dv(GitHub profile, opens in a new tab) View on GitHubThis PR:
- Fixes the types of
injectQueries - Add type tests for
injectQueries - Adds initial tests for
injectQueriesruntime - Fixes runtime behavior of
injectQueries
TODO:#
- Figure out where to add
signalProxy
Summary by CodeRabbit#
- New Features
- Updated multi-query injection API to accept function-based options and return a reactive signal, enabling more flexible and responsive configuration.
- Improved per-query result typing for clearer, more accurate type inference.
- Tests
- Added integration tests validating asynchronous multi-query behavior and state updates.
- Added type-level tests to ensure correct inference across various usage patterns.
- Chores
- Upgraded Angular testing library to v18 for improved tooling and compatibility in development.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: angular-query-experimental
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-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-simple
- @tanstack/query-example-solid-start-streaming
- @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-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-prefetching
- @tanstack/query-example-nextjs-suspense-streaming
- @tanstack/query-example-react-offline
- @tanstack/query-example-react-optimistic-updates-cache
- @tanstack/query-example-react-optimistic-updates-ui
- @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-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@8690@tanstack/eslint-plugin-query
npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@8690@tanstack/query-async-storage-persister
npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@8690@tanstack/query-broadcast-client-experimental
npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@8690@tanstack/query-core
npm i https://pkg.pr.new/@tanstack/query-core@8690@tanstack/query-devtools
npm i https://pkg.pr.new/@tanstack/query-devtools@8690@tanstack/query-persist-client-core
npm i https://pkg.pr.new/@tanstack/query-persist-client-core@8690@tanstack/query-sync-storage-persister
npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@8690@tanstack/react-query
npm i https://pkg.pr.new/@tanstack/react-query@8690@tanstack/react-query-devtools
npm i https://pkg.pr.new/@tanstack/react-query-devtools@8690@tanstack/react-query-next-experimental
npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@8690@tanstack/react-query-persist-client
npm i https://pkg.pr.new/@tanstack/react-query-persist-client@8690@tanstack/solid-query
npm i https://pkg.pr.new/@tanstack/solid-query@8690@tanstack/solid-query-devtools
npm i https://pkg.pr.new/@tanstack/solid-query-devtools@8690@tanstack/solid-query-persist-client
npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@8690@tanstack/svelte-query
npm i https://pkg.pr.new/@tanstack/svelte-query@8690@tanstack/svelte-query-devtools
npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@8690@tanstack/svelte-query-persist-client
npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@8690@tanstack/vue-query
npm i https://pkg.pr.new/@tanstack/vue-query@8690@tanstack/vue-query-devtools
npm i https://pkg.pr.new/@tanstack/vue-query-devtools@8690commit:
26d7f36Hey @crutchcorn! I just noticed you dropped a PR to fix
injectQueries. I've been using a custom build of@tanstack/angular-query-experimentalfrom this PR (https://github.com/TanStack/query/pull/8007) that has been working great for me in production, as I really neededinjectQueriesfor my application.I'm not sure if that MR can serve as an inspiration for your work, or possibly even avoid work altogether?
Should be something like this to proxify the individual queries, but I'm getting errors. I will look into this more.
const resultSignal = computed(() => { const subscriberResult = resultFromSubscriberSignal() const optimisticResult = optimisticCombinedResultSignal() return subscriberResult ?? optimisticResult }) return computed(() => { const result = resultSignal() if (Array.isArray(result)) { return result.map((query) => signalProxy(query)) } return result }) }) as unknown as Signal<TCombinedResult>More todos:
- Should be able to throw an error when
throwOnErroris true - Using
mapon result gives error TS2339: Property map does not exist on type TCombinedResult. - The computed with proxified queries needs to be improved so that new signals are not created for each query when the result changes.
- Align signature with other functions: parameters injectQueriesFn and options
- Persistence
- Should be able to throw an error when
arnoud-dv(GitHub profile, opens in a new tab) assignedarnoud-dv
@arnoud-dv @crutchcorn Are you still working on the feature? Do you need some help?
Yes, help with
injectQueriesis welcome Thomas. I don't have enough time at the moment.Walkthrough#
Refactors injectQueries to accept a function-based options provider and updates public types (InjectQueriesOptions, QueriesOptions, QueriesResults). Implements reactive observer wiring with signals and signalProxy. Adds unit and d.ts tests for new typing and behavior. Updates Angular testing library dev dependency versions in two packages.
Changes#
Cohort / File(s) Summary of changes Dev testing deps packages/angular-query-experimental/package.json,packages/angular-query-persist-client/package.jsonAdd/upgrade dev dependency @testing-library/angularto^18.0.0.API and reactive flow refactor packages/angular-query-experimental/src/inject-queries.tsChange injectQueries signature to accept optionsFn: () => InjectQueriesOptions; add/exportInjectQueriesOptions; reviseQueriesOptionsandQueriesResultstyping to per-query mapping; rework runtime to derive options, observer, and results via signals andsignalProxy.Type-level tests packages/angular-query-experimental/src/__tests__/inject-queries.test-d.tsNew d.ts tests validating TData inference, overloads, skipToken handling, and dynamic query result typing for injectQueries. Runtime tests packages/angular-query-experimental/src/__tests__/inject-queries.test.tsNew integration test verifying two async queries sequence and signal-driven state progression using Angular Testing Library and QueryClient. Sequence Diagram(s)#
sequenceDiagram autonumber actor C as Component participant IQ as injectQueries participant OF as optionsFn() participant QC as QueryClient participant OBS as observerSignal participant RS as resultSignal C->>IQ: call with optionsFn, injector? IQ->>OF: compute options (queries, combine) IQ->>QC: apply defaultQueryOptions IQ->>OBS: create reactive QueriesObserver OBS-->>IQ: optimistic results (signal) OBS-->>IQ: subscribe for updates (untracked) IQ->>RS: merge subscriber/optimistic results RS-->>C: Signal<TCombinedResult> (proxied per-query) note over IQ,OBS: Each query result wrapped via signalProxyEstimated code review effort#
🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related issues#
- TanStack/query#8703 — Tracks the injectQueries refactor and API/type changes implemented here.
Possibly related PRs#
- TanStack/query#9655 — Touches the same injectQueries API surface, relocating/exporting it under experimental paths.
- TanStack/query#9270 — Modifies injectQueries signature, types, and associated tests/docs, overlapping with this refactor.
Poem#
A rabbit twitched its whiskered nose, New signals hum where options rose; Queries hop in tidy lines, Types align like perfect pines; Tests burrow deep to check the trace— Then pop! two carrots, data in place. 🥕🐇
Pre-merge checks and finishing touches#
✅ Passed checks (3 passed)
Check name Status Explanation Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled. Title Check ✅ Passed The title "[WIP] Angular injectQueries fixes" directly reflects the primary change set (fixes to injectQueries in the Angular package) and is concise and relevant for reviewers; the only drawback is the "[WIP]" prefix which is extraneous for a merge-ready title. Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped. ✨ Finishing touches
- 📝 Generate Docstrings
🧪 Generate unit tests
- Create PR with unit tests
- Post copyable unit tests in a comment
- Commit unit tests in branch `angular-inject-queries-fixes`
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 3f5156db7e6c6cb7eb6b3a7033498b402d80cde7 and 26d7f36575dcc568a2c110d7b4497361a8f270f6.
📒 Files selected for processing (1)
packages/angular-query-experimental/src/__tests__/inject-queries.test.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/angular-query-experimental/src/tests/inject-queries.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Preview
- GitHub Check: Test
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 `@coderabbitai help` to get the list of available commands and usage tips.Actionable comments posted: 5
🧹 Nitpick comments (5)
packages/angular-query-experimental/src/__tests__/test-utils.ts (2)
50-53: Prefer safe hasOwnProperty.Use Object.prototype.hasOwnProperty.call to avoid prototype pitfalls.
- return ( - component.hasOwnProperty(property) && (component as any)[property][SIGNAL] - ) + return ( + Object.prototype.hasOwnProperty.call(component, property) && + (component as any)[property][SIGNAL] + )
59-68: Forward-compat risk: using @angular/core/primitives/signals.These are private internals and may change across Angular minors. Keep an eye on Angular 20.x release notes; if instability shows up, consider an adapter or gated usage in tests only.
packages/angular-query-experimental/src/inject-queries.ts (2)
259-269: Ensure observer is destroyed on component destroy (no listeners path).If we never subscribe (e.g., during restore), the instance isn’t destroyed. Register destroy hook.
const observerSignal = (() => { let instance: QueriesObserver<TCombinedResult> | null = null return computed(() => { return (instance ||= new QueriesObserver<TCombinedResult>( queryClient, defaultedQueries(), optionsSignal() as QueriesObserverOptions<TCombinedResult>, )) }) })() + destroyRef.onDestroy(() => observerSignal().destroy())
1-37: Types: skipToken widening looks fine; consider using typeof for tighter inference.type SkipTokenForCreateQueries = symbolworks, buttypeof skipTokenwould preserve the unique symbol for stricter discriminants.packages/angular-query-experimental/src/__tests__/inject-queries.test.tsx (1)
68-71: Stabilize snapshot collection to avoid over-collection.If options change or additional intermediate states appear, this may push >3 snapshots. Consider guarding pushes with a simple dedupe on JSON.stringify or reading only
datafields.📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 94ee0ebeff9b65c2ad381ea866389f925865113c and 3d4612258bf2430eb269496bfa3e5626e0bc4da3.
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (5)
packages/angular-query-experimental/package.json(1 hunks)packages/angular-query-experimental/src/__tests__/inject-queries.test-d.ts(1 hunks)packages/angular-query-experimental/src/__tests__/inject-queries.test.tsx(1 hunks)packages/angular-query-experimental/src/__tests__/test-utils.ts(1 hunks)packages/angular-query-experimental/src/inject-queries.ts(8 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-02T17:57:33.184Z
Learnt from: TkDodo PR: TanStack/query#9612 File: packages/query-async-storage-persister/src/asyncThrottle.ts:0-0 Timestamp: 2025-09-02T17:57:33.184Z Learning: When importing from tanstack/query-core in other TanStack Query packages like query-async-storage-persister, a workspace dependency "tanstack/query-core": "workspace:*" needs to be added to the package.json.Applied to files:
packages/angular-query-experimental/package.json
🧬 Code graph analysis (2)
packages/angular-query-experimental/src/__tests__/inject-queries.test.tsx (2)
packages/angular-query-experimental/src/inject-queries.ts (1)
injectQueries(223-325)
packages/angular-query-experimental/src/__tests__/test-utils.ts (1)
evaluateSignals(10-29)
packages/angular-query-experimental/src/inject-queries.ts (3)
packages/angular-query-experimental/src/types.ts (3)
CreateQueryOptions(41-55)CreateQueryResult(126-129)DefinedCreateQueryResult(134-139)
packages/query-core/src/queriesObserver.ts (4)
result(195-210)QueriesObserver(35-286)QueriesObserverOptions(29-33)observer(263-269)
packages/angular-query-experimental/src/signal-proxy.ts (1)
signalProxy(14-46)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Test
- GitHub Check: Preview
🔇 Additional comments (5)
packages/angular-query-experimental/package.json (1)
77-77: Dev dep OK; verify Angular 20 compatibility matrix."@testing-library/angular@^18" should work, but please confirm it aligns with Angular 20 and our Node/TS versions used in CI.
packages/angular-query-experimental/src/inject-queries.ts (1)
218-229: API note: optionsFn DI usage clarified.Nice move to optionsFn. With the
ngInjectorfix above,inject()withinoptionsFnwill be safe across re-evaluations.packages/angular-query-experimental/src/__tests__/inject-queries.test.tsx (1)
35-45: Test structure LGTM.Nicely exercises two concurrent queries and UI rendering with zoneless change detection.
packages/angular-query-experimental/src/__tests__/inject-queries.test-d.ts (2)
131-145: Type test for conditional skipToken is solid.Covers the widened union and expected
data(): number | undefined.
147-176: Great coverage for dynamic mixed queries.The branded Signal assertion reduces regressions in result typing.
@@ -7,7 +7,7 @@77 /* eslint jsdoc/require-jsdoc: 0, jsdoc/require-param: 0 */8899 // Evaluate all signals on an object and return the result10-function evaluateSignals<T extends Record<string, any>>(10+export function evaluateSignals<T extends Record<string, any>>(1111 obj: T,1212 ): { [K in keyof T]: ReturnType<T[K]> } {1313 const result: Partial<{ [K in keyof T]: ReturnType<T[K]> }> = {}🛠️ Refactor suggestion
Tighten evaluateSignals return type to signal keys only.
Current return type claims all keys, but only signal properties are evaluated. Narrow it to signal keys to avoid misleading types.
-export function evaluateSignals<T extends Record<string, any>>( - obj: T, -): { [K in keyof T]: ReturnType<T[K]> } { +export function evaluateSignals<T extends Record<string, any>>( + obj: T, +): { + [K in keyof T as T[K] extends Signal<any> ? K : never]: T[K] extends Signal< + infer R + > + ? R + : never +} { const result: Partial<{ [K in keyof T]: ReturnType<T[K]> }> = {}📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export function evaluateSignals<T extends Record<string, any>>( obj: T, ): { [K in keyof T as T[K] extends Signal<any> ? K : never]: T[K] extends Signal< infer R > ? R : never } { const result: Partial<{ [K in keyof T]: ReturnType<T[K]> }> = {}🤖 Prompt for AI Agents
In packages/angular-query-experimental/src/__tests__/test-utils.ts around lines 10-13, the evaluateSignals return type currently claims all keys of T but only evaluates signal properties; change the generic return mapping to include only those keys whose values are signals (or functions returning values) using a conditional key remap (e.g., K in keyof T as T[K] extends Signal | (() => any) ? K : never) and ReturnType<T[K]> for the value type, and update the local result/Partial typing to match the narrowed mapped type so the function signature accurately reflects that non-signal keys are omitted.@@ -223,3 +234,13 @@223234 const queryClient = inject(QueryClient)224235 const isRestoring = injectIsRestoring()225236237+ /**238+ * Signal that has the default options from query client applied239+ * computed() is used so signals can be inserted into the options240+ * making it reactive. Wrapping options in a function ensures embedded expressions241+ * are preserved and can keep being applied after signal changes242+ */243+ const optionsSignal = computed(() => {244+ return runInInjectionContext(injector ?? ngInjector, () => optionsFn())245+ })246+⚠️ Potential issue
Undefined identifier 'ngInjector' breaks DI at runtime.
ngInjectoris not defined. Computed will throw the first time it runs.return runInInjectionContext(injector ?? inject(Injector), () => { const destroyRef = inject(DestroyRef) const ngZone = inject(NgZone) const queryClient = inject(QueryClient) const isRestoring = injectIsRestoring() + // Capture the active injector for re-use inside computed/Effects + const ngInjector = inject(Injector) /** * Signal that has the default options from query client applied @@ - const optionsSignal = computed(() => { - return runInInjectionContext(injector ?? ngInjector, () => optionsFn()) - }) + const optionsSignal = computed(() => + runInInjectionContext(ngInjector, () => optionsFn()), + )📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// Capture the active injector for re-use inside computed/Effects const ngInjector = inject(Injector) const optionsSignal = computed(() => runInInjectionContext(ngInjector, () => optionsFn()), )🤖 Prompt for AI Agents
In packages/angular-query-experimental/src/inject-queries.ts around lines 243 to 246, the fallback identifier "ngInjector" is undefined and causes a runtime DI error; replace the undefined identifier by calling Angular's inject(Injector) directly (e.g. use injector ?? inject(Injector)) and ensure you import both inject and Injector from @angular/core at the top of the file so the computed callback uses a valid injector at runtime.@@ -263,5 +296,17 @@263- : ngZone.runOutsideAngular(() =>264- observer.subscribe(notifyManager.batchCalls(result.set)),265- )266- destroyRef.onDestroy(unsubscribe)296+ const observer = observerSignal()297+ const [_optimisticResult, getCombinedResult] = optimisticResultSignal()298+299+ untracked(() => {300+ const unsubscribe = isRestoring()301+ ? () => undefined302+ : ngZone.runOutsideAngular(() =>303+ observer.subscribe(304+ notifyManager.batchCalls((state) => {305+ resultFromSubscriberSignal.set(getCombinedResult(state))306+ }),307+ ),308+ )309+310+ destroyRef.onDestroy(unsubscribe)311+ })267312 })⚠️ Potential issue
Subscription leak on options changes; use effect cleanup.
Each re-run re-subscribes without unsubscribing the previous listener. Use
onCleanupto prevent duplicate listeners.- effect(() => { + effect((onCleanup) => { const observer = observerSignal() const [_optimisticResult, getCombinedResult] = optimisticResultSignal() untracked(() => { const unsubscribe = isRestoring() ? () => undefined : ngZone.runOutsideAngular(() => observer.subscribe( notifyManager.batchCalls((state) => { resultFromSubscriberSignal.set(getCombinedResult(state)) }), ), ) destroyRef.onDestroy(unsubscribe) + onCleanup(unsubscribe) }) })📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
effect((onCleanup) => { const observer = observerSignal() const [_optimisticResult, getCombinedResult] = optimisticResultSignal() untracked(() => { const unsubscribe = isRestoring() ? () => undefined : ngZone.runOutsideAngular(() => observer.subscribe( notifyManager.batchCalls((state) => { resultFromSubscriberSignal.set(getCombinedResult(state)) }), ), ) destroyRef.onDestroy(unsubscribe) onCleanup(unsubscribe) }) })🤖 Prompt for AI Agents
In packages/angular-query-experimental/src/inject-queries.ts around lines 295 to 312, the effect re-subscribes on each run without removing the previous subscription causing a leak; change the effect to register a cleanup that calls the previously created unsubscribe function (e.g., declare unsubscribe in the outer scope, assign it inside untracked, and call it from onCleanup/returned cleanup) so each re-run unsubscribes the prior listener, and keep destroyRef.onDestroy to also call unsubscribe to cover component teardown.@@ -267,4 +306,19 @@306+ }),307+ ),308+ )309+310+ destroyRef.onDestroy(unsubscribe)311+ })267312 })268313269- return result270- })314+ const resultSignal = computed(() => {315+ const subscriberResult = resultFromSubscriberSignal()316+ const optimisticResult = optimisticCombinedResultSignal()317+ return subscriberResult ?? optimisticResult318+ })319+320+ return computed(() => {321+ const result = resultSignal()322+ return result.map((query) => signalProxy(signal(query)))323+ })324+ }) as unknown as Signal<TCombinedResult>🛠️ Refactor suggestion
Use computed instead of signal for per-item wrapping.
signal(query)freezes the reference; updates rely on recreating proxies. Usingcomputed(() => query)lets the proxy track the latest item while still allowing memoization strategies later.🤖 Prompt for AI Agents
In packages/angular-query-experimental/src/inject-queries.ts around lines 320 to 324, the current per-item wrapper uses signal(query) which freezes the reference and forces proxy recreation; replace signal(query) with computed(() => query) so the proxy can track the latest item while keeping memoization possibilities. Update the mapping to return signalProxy(computed(() => query)) (or equivalent helper) for each query, and add/adjust imports for computed if not already imported.
⚠️ Potential issue
Do not assume combined result is an array.
When
combinereturns a non-array,result.mapwill throw. Handle arrays and objects.- return computed(() => { - const result = resultSignal() - return result.map((query) => signalProxy(signal(query))) - }) + return computed(() => { + const result = resultSignal() as any + if (Array.isArray(result)) { + // Proxify each query result + return result.map((query: any) => signalProxy(computed(() => query))) + } + // Proxify the combined object result + return signalProxy(computed(() => result)) + })📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
return computed(() => { const result = resultSignal() as any if (Array.isArray(result)) { // Proxify each query result return result.map((query: any) => signalProxy(computed(() => query))) } // Proxify the combined object result return signalProxy(computed(() => result)) }) }) as unknown as Signal<TCombinedResult>github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: angular-query-persist-client
Codecov Report#
:x: Patch coverage is
94.44444%with2 linesin your changes missing coverage. Please review. :white_check_mark: Project coverage is 46.19%. Comparing base (a2151d2) to head (26d7f36). :warning: Report is 2 commits behind head on main.Additional details and impacted files
@@ Coverage Diff @@ ## main #8690 +/- ## ========================================== + Coverage 45.77% 46.19% +0.42% ========================================== Files 213 213 Lines 8429 8453 +24 Branches 1916 1920 +4 ========================================== + Hits 3858 3905 +47 + Misses 4124 4105 -19 + Partials 447 443 -4- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Actionable comments posted: 0
🧹 Nitpick comments (5)
packages/angular-query-experimental/src/__tests__/inject-queries.test.ts (5)
30-30: Rename suite to reflect the API under test.Name currently says "useQueries" but the test targets injectQueries.
-describe('useQueries', () => { +describe('injectQueries', () => {
69-71: Effect won’t react if proxies/array become stable (brittle to future optimizations).evaluateSignals uses untracked; the effect currently re-runs only because result() changes identity. If proxies/array are made stable (as intended), this will stop capturing updates. Track inner signals explicitly.
- _pushResults = effect(() => { - results.push(this.result().map(evaluateSignals)) - }) + _pushResults = effect(() => { + // Track inner signal values so the effect re-runs even with stable proxies/array + const snapshot = this.result().map((q) => ({ data: q.data() })) + results.push(snapshot) + })
26-28: Remove empty afterEach.No-op block with commented code; drop for cleanliness.
-afterEach(() => { - // vi.useRealTimers() -}) +
37-49: Template can avoid extra toString helper.Angular interpolation stringifies values; helper is unnecessary noise.
- template: ` - <div> - <div> - data1: {{ toString(result()[0].data() ?? 'null') }}, data2: - {{ toString(result()[1].data() ?? 'null') }} - </div> - </div> - `, + template: ` + <div> + <div> + data1: {{ result()[0].data() ?? 'null' }}, data2: {{ result()[1].data() ?? 'null' }} + </div> + </div> + `, ... - toString(val: any) { - return String(val) - }
74-81: Optional: use findByText for clearer async intent.Minor readability; functionally the same.
- await waitFor(() => rendered.getByText('data1: 1, data2: 2')) + await rendered.findByText('data1: 1, data2: 2')📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 3d4612258bf2430eb269496bfa3e5626e0bc4da3 and d46ea2080b4a0697058b875aa85cf612f898a836.
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (4)
packages/angular-query-experimental/package.json(1 hunks)packages/angular-query-experimental/src/__tests__/inject-queries.test.ts(1 hunks)packages/angular-query-experimental/src/inject-queries.ts(8 hunks)packages/angular-query-persist-client/package.json(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/angular-query-experimental/src/inject-queries.ts
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-02T17:57:33.184Z
Learnt from: TkDodo PR: TanStack/query#9612 File: packages/query-async-storage-persister/src/asyncThrottle.ts:0-0 Timestamp: 2025-09-02T17:57:33.184Z Learning: When importing from tanstack/query-core in other TanStack Query packages like query-async-storage-persister, a workspace dependency "tanstack/query-core": "workspace:*" needs to be added to the package.json.Applied to files:
packages/angular-query-persist-client/package.jsonpackages/angular-query-experimental/package.json
🧬 Code graph analysis (1)
packages/angular-query-experimental/src/__tests__/inject-queries.test.ts (2)
packages/angular-query-experimental/src/inject-queries.ts (1)
injectQueries(221-331)
packages/angular-query-experimental/src/__tests__/test-utils.ts (1)
evaluateSignals(10-29)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Test
🔇 Additional comments (2)
packages/angular-query-persist-client/package.json (1)
67-67: Confirm @testing-library/angular v18 requires Angular 20; verify monorepo- Confirmed: official v18 changelog raises the minimum Angular version to 20.
- Action: ensure packages/angular-query-persist-client/package.json and every workspace package use @angular/core >= 20 (or pin @testing-library/angular to ^17).
- Verification: automated repo scan here failed with fd/jq errors — re-run the package.json check locally and confirm all packages' @angular/core and @testing-library/angular versions.
packages/angular-query-experimental/package.json (1)
97-97: Approve — devDependency addition OK; compatibility and cross-package consistency verified.Testing Library v18 officially supports Angular 20 (Testing Library docs / README). Repository scan: ^18.0.0 appears only in packages/angular-query-experimental/package.json and packages/angular-query-persist-client/package.json — no conflicting majors detected.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/angular-query-experimental/src/__tests__/test-utils.ts (1)
1-47: Restore or remove stale test helpers (expectSignals / evaluateSignals)test-utils no longer exports these helpers but tests and ESLint still reference them — update tests or reintroduce the helpers.
- packages/angular-query-experimental/src/tests/test-utils.ts — current exports: setSignalInputs, setFixtureSignalInputs (no expectSignals/evaluateSignals).
- packages/angular-query-experimental/src/tests/inject-infinite-query.test.ts — imports/calls expectSignals.
- packages/angular-query-experimental/src/tests/inject-mutation.test.ts — imports/calls expectSignals (and imports setFixtureSignalInputs).
- packages/angular-query-experimental/eslint.config.js — vitest/expect-expect assertFunctionNames includes 'expectSignals'.
Action: either re-add the missing helpers to test-utils or update the tests to use the new helpers and remove 'expectSignals' from the ESLint config.
♻️ Duplicate comments (1)
packages/angular-query-experimental/src/__tests__/test-utils.ts (1)
1-1: Removal ofevaluateSignals/expectSignalslooks good and resolves the prior typing concern.🧹 Nitpick comments (5)
packages/angular-query-experimental/src/__tests__/test-utils.ts (5)
1-3: Avoid relying solely on private Angular signals API; prefer public.set(...)with a guarded fallback.@angular/core/primitives/signalsis private and can break between Angular releases. UseinputSignal.set(value)when present, and fall back tosignalSetFn(...[SIGNAL])only if needed.- import { SIGNAL, signalSetFn } from '@angular/core/primitives/signals' + import { SIGNAL, signalSetFn } from '@angular/core/primitives/signals' // test-only fallback; prefer .set(...) import type { InputSignal } from '@angular/core'
7-11: Make the updatable mapPartialso callers can set a subset of inputs.As written, all InputSignal keys are required. Tests often set only a few.
-type ToSignalInputUpdatableMap<T> = { - [K in keyof T as T[K] extends InputSignal<any> - ? K - : never]: T[K] extends InputSignal<infer Value> ? Value : never -} +type ToSignalInputUpdatableMap<T> = Partial<{ + [K in keyof T as T[K] extends InputSignal<any> + ? K + : never]: T[K] extends InputSignal<infer Value> ? Value : never +}>
13-20: Harden the type guard and avoid directhasOwnPropertycalls.Use
Object.prototype.hasOwnProperty.calland coerce to boolean; widen key type toPropertyKey.-function componentHasSignalInputProperty<TProperty extends string>( - component: object, - property: TProperty, -): component is { [key in TProperty]: InputSignal<unknown> } { - return ( - component.hasOwnProperty(property) && (component as any)[property][SIGNAL] - ) -} +function componentHasSignalInputProperty<TProperty extends PropertyKey>( + component: object, + property: TProperty, +): component is { [key in TProperty]: InputSignal<unknown> } { + return ( + Object.prototype.hasOwnProperty.call(component, property) && + !!(component as any)?.[property]?.[SIGNAL] + ) +}
26-35: Prefer.set(...); handle undefineds; avoidfor..inprototype leaks.- Iterate via
Object.entriesand skipundefinedvalues. - Use public
set(...)when available; fallback to privatesignalSetFnfor older versions.
-export function setSignalInputs<T extends NonNullable<unknown>>( - component: T, - inputs: ToSignalInputUpdatableMap<T>, -) { - for (const inputKey in inputs) { - if (componentHasSignalInputProperty(component, inputKey)) { - signalSetFn(component[inputKey][SIGNAL], inputs[inputKey]) - } - } -} +export function setSignalInputs<T extends object>( + component: T, + inputs: ToSignalInputUpdatableMap<T>, +) { + for (const [key, value] of Object.entries(inputs) as [keyof T, unknown][]) { + if (value === undefined) continue + if (componentHasSignalInputProperty(component, key as any)) { + const sig = (component as any)[key] + if (typeof sig?.set === 'function') { + sig.set(value) + } else { + signalSetFn(sig[SIGNAL], value) + } + } + } +}
37-46: Loosenoptionsshape and default todetectChanges: true.-export function setFixtureSignalInputs<T extends NonNullable<unknown>>( - componentFixture: ComponentFixture<T>, - inputs: ToSignalInputUpdatableMap<T>, - options: { detectChanges: boolean } = { detectChanges: true }, -) { - setSignalInputs(componentFixture.componentInstance, inputs) - if (options.detectChanges) { - componentFixture.detectChanges() - } -} +export function setFixtureSignalInputs<T extends object>( + componentFixture: ComponentFixture<T>, + inputs: ToSignalInputUpdatableMap<T>, + options?: { detectChanges?: boolean }, +) { + setSignalInputs(componentFixture.componentInstance, inputs) + if (options?.detectChanges ?? true) { + componentFixture.detectChanges() + } +}📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between d6cb12dbba5de4d204c70b3f1dc09f862801d56c and 3f5156db7e6c6cb7eb6b3a7033498b402d80cde7.
📒 Files selected for processing (2)
packages/angular-query-experimental/src/__tests__/inject-queries.test.ts(1 hunks)packages/angular-query-experimental/src/__tests__/test-utils.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/angular-query-experimental/src/tests/inject-queries.test.ts
@tomalaforge I merged this PR as it's definitely an improvement and long lived branches are a lot of work to keep up to date. However injectQueries isn't functional yet so can still be worked on. I moved it to a separate export so injectQueries won't hold up a stable release of the other APIs.
arnoud-dv(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
View your CI Pipeline Execution ↗ for commit 26d7f36575dcc568a2c110d7b4497361a8f270f6
nx affected --targets=test:sherif,test:knip,tes...nx run-many --target=build --exclude=examples/*...☁️ Nx Cloud last updated this comment at
2025-09-18 17:42:21UTC