Skip to content

Conversation

@visz11
Copy link
Collaborator

@visz11 visz11 commented Oct 14, 2025

CodeAnt-AI Description

Fix query client being undefined and prevent crashes for dependent queries during navigation

What Changed

  • Queries now always receive a valid query client so queries no longer start with an undefined client and fail at runtime
  • Dependent queries that rely on parent query data during route changes complete without triggering the error boundary and the child data appears after navigation
  • A test reproducing a route transition with a parent and dependent child query was added to prevent regressions; the router test dependency was added to support this scenario

Impact

✅ Fewer query startup errors
✅ No route-change crashes for dependent queries
✅ Reliable child data rendering after navigation

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Summary by CodeRabbit

  • New Features
    • Improved reliability for dependent queries when navigating between routes, especially under Suspense and ErrorBoundary.
  • Bug Fixes
    • Stabilized initial query client handling to reduce edge-case errors on first render.
  • Tests
    • Added tests covering dependent queries across routes to validate correct fetching and rendering behavior without errors.
  • Chores
    • Added a router development dependency to support routing-based test scenarios.

@codeant-ai
Copy link

codeant-ai bot commented Oct 14, 2025

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@gemini-code-assist
Copy link

Summary of Changes

Hello @visz11, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new, robust test case for useQuery to ensure proper handling of dependent queries, especially when integrated with SolidJS routing. It also includes a minor but potentially significant adjustment to the createMemo usage in useBaseQuery to enhance client memoization. These changes aim to improve the reliability and correctness of solid-query in complex application flows involving data dependencies and navigation.

Highlights

  • New Test Case for Dependent Queries: A comprehensive test has been added to useQuery.test.tsx to validate the behavior of dependent queries, particularly in a routing environment, referencing a known issue in react-query ([solid-query] Dependent queries throw client() is undefined error TanStack/query#8469).
  • Router Integration for Testing: The @solidjs/router library has been introduced as a dev dependency and utilized in the new test to simulate real-world routing scenarios for solid-query.
  • useBaseQuery Memoization Update: The createMemo call within useBaseQuery.ts has been updated to provide an initial value for the queryClient memo, potentially improving its stability or reactivity.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Oct 14, 2025

Walkthrough

Added a devDependency for routing, introduced a new test validating dependent queries across routes, and adjusted memo initialization in useBaseQuery to include an explicit initial value.

Changes

Cohort / File(s) Summary of Changes
Package manifest update
packages/solid-query/package.json
Added devDependency @solidjs/router with version ^0.15.3.
Hook initialization tweak
packages/solid-query/src/useBaseQuery.ts
Updated createMemo to include an explicit initial value: createMemo(() => useQueryClient(queryClient?.()), useQueryClient(queryClient?.())).
Routing-based dependent query test
packages/solid-query/src/__tests__/useQuery.test.tsx
Added test for dependent queries across routes using @solidjs/router (MemoryRouter, Routes, Route), Suspense, and ErrorBoundary. Verifies child query fetches after parent data is available and no errors are raised.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as Test Runner
  participant App as App (MemoryRouter)
  participant QC as QueryClientProvider
  participant P as Parent useQuery ['parent']
  participant C as Child useQuery ['sub', parent.id]

  U->>App: Mount App at index route
  App->>QC: Provide QueryClient context
  Note over App,QC: Parent query preloaded in cache

  U->>App: Navigate to /sub
  App->>P: Read parent data (cache)
  P-->>App: Return parent { id }
  App->>C: Initialize child query with key ['sub', parent.id]
  C->>QC: Fetch child data via QueryClient
  QC-->>C: child data (e.g., "child123")
  C-->>App: Render child data
  App-->>U: Output shows child data, no errors
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit hops through routes so spry,
Parent first, then child draws nigh.
A memo wakes with steady start,
Queries dance in cached-art.
DevDeps bloom, the router’s in,
Tests now grin—let fetches begin! 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title “Clone main” does not describe any of the actual changes in this PR, which adds a router devDependency, introduces a dependent queries test using MemoryRouter, and adjusts the memo initialization in useBaseQuery. It is unrelated to the modifications and fails to communicate the primary purpose of the changeset. A reviewer scanning history would not understand what this PR achieves based on the title alone. Please update the title to clearly and concisely summarize the main changes, such as “Add dependent queries test with Solid JS routing and update useBaseQuery memo initialization.”
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch clone-main

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 and usage tips.

@codeant-ai codeant-ai bot added the size:L This PR changes 100-499 lines, ignoring generated files label Oct 14, 2025
@refacto-visz
Copy link

refacto-visz bot commented Oct 14, 2025

Clone main

TL;DR: Adds dependent query test case and fixes query client memoization in solid-query package.


Refacto PR Summary

Implements test coverage for dependent queries in routing scenarios and resolves query client memoization issues.
This PR addresses a critical bug in solid-query where dependent queries could fail during route navigation. The fix modifies the useBaseQuery hook to properly memoize the query client, preventing stale references when components unmount and remount during navigation. Additionally, a comprehensive test case validates the dependent query behavior using SolidJS router integration, ensuring queries properly chain when navigating between routes with parent-child query relationships.

Change Highlights

Click to expand
  • packages/solid-query/src/useBaseQuery.ts: Fixed query client memoization with proper equality check
  • packages/solid-query/src/tests/useQuery.test.tsx: Added dependent queries routing test case
  • packages/solid-query/package.json: Added @solidjs/router as dev dependency for testing

Sequence Diagram

sequenceDiagram
    participant R as Router
    participant C as Component
    participant Q as useQuery
    participant QC as QueryClient
    participant API as QueryFn
    
    R->>C: Navigate to /sub
    C->>Q: Parent query (id: 123)
    Q->>QC: Get cached data
    QC-->>Q: Return parent data
    Q-->>C: Parent result
    C->>Q: Child query (depends on parent.id)
    Q->>API: Fetch child data
    API-->>Q: Return child123
    Q-->>C: Child result
    C-->>R: Render child123
Loading

Testing Guide

Click to expand
  1. Route navigation test: Navigate from index to /sub route, verify dependent queries execute correctly without errors
  2. Query dependency chain: Ensure child query waits for parent query data before executing
  3. Error boundary validation: Confirm no errors thrown during route transitions with dependent queries
  4. Data consistency: Verify child query receives correct parent data (child123) after navigation
  5. Memory management: Test multiple route navigations to ensure no memory leaks in query client references

@visz11
Copy link
Collaborator Author

visz11 commented Oct 14, 2025

/refacto-visz

@refacto-visz
Copy link

refacto-visz bot commented Oct 14, 2025

Refacto is reviewing this PR. Please wait for the review comments to be posted.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a fix for dependent queries, particularly in scenarios involving suspense, along with a corresponding test case. The fix in useBaseQuery.ts adjusts the memoization of the QueryClient to handle reactivity more robustly. The new test case is a valuable addition, though I've suggested a small improvement to remove a sleep call to prevent potential flakiness. The added @solidjs/router dev dependency is appropriate for the new test.

Comment on lines +6117 to +6123
await sleep(200)

expect(errorHandler).not.toHaveBeenCalled()

await waitFor(() => {
expect(rendered.getByText('child123')).toBeInTheDocument()
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using sleep in tests can introduce flakiness. It's generally better to rely on waitFor to check for the expected outcome.

In this case, if the waitFor assertion for the success state (child123) passes, it implies that no error was thrown and the errorHandler was not called. You can safely move the expect(errorHandler).not.toHaveBeenCalled() assertion after the waitFor block and remove the sleep, making the test more robust.

    await waitFor(() => {
      expect(rendered.getByText('child123')).toBeInTheDocument()
    })

    expect(errorHandler).not.toHaveBeenCalled()

@refacto-visz
Copy link

refacto-visz bot commented Oct 14, 2025

Code Review: Query Client Memo Implementation

👍 Well Done
Comprehensive Test Coverage

Added router navigation test with dependent queries prevents future regressions and validates query behavior during navigation transitions

📁 Selected files for review (4)
  • packages/solid-query/package.json
  • packages/solid-query/src/__tests__/useQuery.test.tsx
  • packages/solid-query/src/useBaseQuery.ts
  • pnpm-lock.yaml
🎯 Custom Instructions
✅ Applied Instructions
Organization Guidelines
  • Avoid commented code in actual codebases
  • Hardcoding of variables

Scope: All files

📝 Additional Comments
packages/solid-query/src/__tests__/useQuery.test.tsx (4)
Async Query Logic

Child query function accesses parent.data?.id within async queryFn but parent data may be stale when async operation executes. Query key uses parent.data?.id for dependency tracking but queryFn execution timing could create race conditions.

Standards:

  • Algorithm-Correctness-Async-Logic
  • Logic-Verification-Race-Conditions
Test Async Timing

Fixed sleep duration creates timing dependency that may cause test flakiness in different execution environments. Race conditions between query resolution and test assertions could lead to intermittent test failures.

Standards:

  • ISO-IEC-25010-Reliability-Maturity
  • SRE-Testing-Reliability
Test Organization Pattern

Large test function (73 lines) handles multiple concerns including router setup, component definition, and assertion logic. This reduces test maintainability and makes debugging more difficult.

Standards:

  • Clean-Code-Functions
  • Maintainability-Quality-Testability
Test Route Navigation

Route navigation test uses synchronous history.set followed by immediate sleep creating timing dependency. Asynchronous navigation completion may vary causing test flakiness.

Standards:

  • ISO-IEC-25010-Performance-Efficiency-Time-Behavior
  • Testing-Pattern-Async-Navigation
packages/solid-query/package.json (1)
Router Dependency Scope

Router dependency added to devDependencies for testing purposes. Verify this dependency is only used in test environments and not inadvertently included in production builds.

Standards:

  • CWE-1104

Comment on lines +119 to +122
const client = createMemo(
() => useQueryClient(queryClient?.()),
useQueryClient(queryClient?.()),
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query Client Equality

Initial value parameter in createMemo causes equality comparison between function result and initial value on every evaluation. This breaks memoization when query client instances differ, leading to unnecessary re-computations and potential query observer recreation.

  const client = createMemo(
    () => useQueryClient(queryClient?.())
  )
Commitable Suggestion
Suggested change
const client = createMemo(
() => useQueryClient(queryClient?.()),
useQueryClient(queryClient?.()),
)
const client = createMemo(
() => useQueryClient(queryClient?.())
)
Standards
  • ISO-IEC-25010-Reliability-Maturity
  • SRE-Performance-Reliability

Comment on lines +119 to +122
const client = createMemo(
() => useQueryClient(queryClient?.()),
useQueryClient(queryClient?.()),
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memo Equality Comparison

Memo equality comparison uses function call result as equality check causing unnecessary re-computations. The useQueryClient call executes on every memo evaluation instead of providing stable equality reference.

Standards
  • ISO-IEC-25010-Performance-Efficiency-Time-Behavior
  • Optimization-Pattern-Memoization-Efficiency

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/solid-query/src/useBaseQuery.ts (1)

119-123: Good fix: initialize memo with an explicit client.

This avoids a transient undefined on first read and stabilizes updates. Minor micro-optimization: compute the initial client once.

-  const client = createMemo(
-    () => useQueryClient(queryClient?.()),
-    useQueryClient(queryClient?.()),
-  )
+  const initialClient = useQueryClient(queryClient?.())
+  const client = createMemo(
+    () => useQueryClient(queryClient?.()),
+    initialClient,
+  )
packages/solid-query/src/__tests__/useQuery.test.tsx (1)

6051-6124: Dependent-queries-across-routes test adds valuable coverage; consider flakiness guard.

Test reads well and validates the regression. To reduce timing flakiness, you can drop the fixed sleep(200) and assert the absence of errors after the child renders, or gate the negative assertion behind a waitFor on child render.

Example:

-    await sleep(200)
-
-    expect(errorHandler).not.toHaveBeenCalled()
-
-    await waitFor(() => {
-      expect(rendered.getByText('child123')).toBeInTheDocument()
-    })
+    await waitFor(() => {
+      expect(rendered.getByText('child123')).toBeInTheDocument()
+    })
+    expect(errorHandler).not.toHaveBeenCalled()

Alternatively, set a small waitFor timeout for the negative assertion if you still want a pre-child check.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a5990e and 49addbc.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • packages/solid-query/package.json (1 hunks)
  • packages/solid-query/src/__tests__/useQuery.test.tsx (3 hunks)
  • packages/solid-query/src/useBaseQuery.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/solid-query/src/useBaseQuery.ts (1)
packages/solid-query/src/QueryClientProvider.tsx (1)
  • useQueryClient (14-25)
packages/solid-query/src/__tests__/useQuery.test.tsx (3)
packages/solid-query/src/__tests__/utils.tsx (2)
  • createQueryClient (35-37)
  • sleep (51-55)
packages/solid-query/src/useQuery.ts (1)
  • useQuery (36-50)
packages/solid-query/src/QueryClientProvider.tsx (1)
  • QueryClientProvider (32-47)
🪛 GitHub Actions: autofix.ci
packages/solid-query/package.json

[error] 1-1: Dependency mismatch detected between package.json and lockfile. Run 'pnpm install' (without --frozen-lockfile) or update the lockfile to reflect changes in package.json.

🔇 Additional comments (3)
packages/solid-query/src/__tests__/useQuery.test.tsx (2)

5-5: Import of Suspense is appropriate.


15-15: Router imports look correct for MemoryRouter usage.

packages/solid-query/package.json (1)

72-72: Lockfile already includes @solidjs/router—no update required
pnpm-lock.yaml records @solidjs/[email protected] and has no unstaged changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants