Skip to content

Conversation

@KATT
Copy link
Member

@KATT KATT commented Mar 14, 2025

Closes #6599

🎯 Changes

Fix handling of falsiness + add regression test

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced pagination behavior by improving the fallback mechanism for page parameters.
    • Refined conditional logic to accurately handle valid paging values, even when they appear falsy.
  • Tests
    • Added a new test to confirm that pagination works correctly with the updated cursor handling.

@KATT KATT requested a review from a team as a code owner March 14, 2025 23:58
@vercel
Copy link

vercel bot commented Mar 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-prisma-starter ✅ Ready (Inspect) Visit Preview Mar 15, 2025 0:00am
og-image ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 15, 2025 0:00am
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 15, 2025 0:00am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2025

Walkthrough

This pull request refines the handling of infinite query parameters. In the trpcInfiniteQueryOptions function, the fallback for initialPageParam now also derives from an input's cursor property if available. In addition, the getClientArgs function is updated to check explicitly for undefined when evaluating pageParam, ensuring accurate cursor assignment. A new test case verifies that these changes correctly support a falsy cursor value in an infinite query context.

Changes

File(s) Change Summary
packages/.../infiniteQueryOptions.ts
packages/.../utils.ts
Refined infinite query parameter handling: updated initialPageParam to fall back on input.cursor if opts.initialCursor is absent, and modified the condition in getClientArgs to check for undefined instead of relying on truthiness of pageParam.
packages/.../infiniteQueryOptions.test.tsx Added a new test case ("falsy cursor") to verify that infinite query functionality correctly processes falsy cursor values and updates data accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Component as MyComponent
    participant Hook as useTRPCInfiniteQuery
    participant Utils as getClientArgs
    participant Server

    User->>Component: Render & Click "Fetch More"
    Component->>Hook: Call infinite query with options
    Hook->>Utils: Prepare client args (check pageParam)
    Utils-->>Hook: Return cursor from opts.initialCursor or input.cursor
    Hook->>Server: Query with cursor value
    Server-->>Hook: Return data and next cursor (if any)
    Hook-->>Component: Update displayed data
Loading

Possibly related PRs

  • fix: infinite query types #6571: Updates to infinite query options and associated type definitions closely relate to the modifications made for cursor handling in this PR.

Poem

I'm a rabbit in the code field, hopping through each line,
New cursor paths spring forth, making my journey fine.
With tests that twirl like carrots in the sun,
Infinite queries dance – the coding fun has begun!
Hopping happy and keen, bugs now run away,
In this garden of logic, I celebrate the day! 🐰

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

 ERR_PNPM_OPTIONAL_DEPS_REQUIRE_PROD_DEPS  Optional dependencies cannot be installed without production dependencies

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 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 9cab92a and 83962fc.

📒 Files selected for processing (3)
  • packages/tanstack-react-query/src/internals/infiniteQueryOptions.ts (1 hunks)
  • packages/tanstack-react-query/src/internals/utils.ts (1 hunks)
  • packages/tanstack-react-query/test/infiniteQueryOptions.test.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: E2E-tests (vercel-edge-runtime)
  • GitHub Check: E2E-tests (tanstack-start)
  • GitHub Check: E2E-tests (.experimental/next-app-dir)
  • GitHub Check: E2E-tests (cloudflare-workers)
  • GitHub Check: E2E-tests (.test/ssg)
  • GitHub Check: E2E-tests (fastify-server)
  • GitHub Check: E2E-tests (.test/diagnostics-big-router)
  • GitHub Check: E2E-tests (.test/internal-types-export)
  • GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 18.x)
  • GitHub Check: e2e-legacy-node (next-prisma-starter, 18.x)
  • GitHub Check: e2e-legacy-node (next-prisma-todomvc, 20.x)
  • GitHub Check: e2e-legacy-node (next-prisma-todomvc, 18.x)
  • GitHub Check: e2e-legacy-node (next-prisma-websockets-starter, 20.x)
  • GitHub Check: E2E-tests (Bun) (bun, ubuntu-latest)
  • GitHub Check: e2e-legacy-node (next-prisma-starter, 20.x)
  • GitHub Check: Release using pkg.pr.new
  • GitHub Check: Test a monorepo using built declaration files
  • GitHub Check: E2E-tests (Deno) (deno-deploy)
  • GitHub Check: test
  • GitHub Check: Lint and auto-fix
🔇 Additional comments (3)
packages/tanstack-react-query/src/internals/infiniteQueryOptions.ts (1)

255-255: Good improvement to handle cursor property in input

This change enhances the fallback mechanism for initialPageParam by using the cursor property from the input when initialCursor is not provided. This allows handling falsy cursor values correctly, which addresses the core issue.

packages/tanstack-react-query/src/internals/utils.ts (1)

39-41: Great fix to properly handle falsy cursor values

The previous implementation used a truthy check which would incorrectly skip falsy values like 0. Changing to an explicit !== undefined check is the right approach as it ensures that all defined values (including falsy ones) are properly set as the cursor.

packages/tanstack-react-query/test/infiniteQueryOptions.test.tsx (1)

444-518: Well-crafted regression test for falsy cursor handling

This test effectively verifies that the fix properly handles a falsy cursor value (0). It's good to see:

  1. A clear reference to the original issue (feat: Allow Falsy Cursor Values in Infinite Query #6599)
  2. Comprehensive test coverage of both initial load and pagination
  3. Proper verification of rendered content to ensure the fix works end-to-end

The test will help prevent regressions in the future.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@railway-app
Copy link

railway-app bot commented Mar 14, 2025

🚅 Deployed to the trpc-pr-6602 environment in trpc-sse-and-websockets

Service Status Web Updated (UTC)
next-sse-chat ◻️ Removed (View Logs) Web Mar 15, 2025 at 10:59 am
next-prisma-websockets-starter ◻️ Removed (View Logs) Mar 15, 2025 at 10:59 am

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 15, 2025

Open in Stackblitz

@trpc/client

npm i https://pkg.pr.new/trpc/trpc/@trpc/client@6602

@trpc/next

npm i https://pkg.pr.new/trpc/trpc/@trpc/next@6602

@trpc/server

npm i https://pkg.pr.new/trpc/trpc/@trpc/server@6602

@trpc/react-query

npm i https://pkg.pr.new/trpc/trpc/@trpc/react-query@6602

@trpc/tanstack-react-query

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

@trpc/upgrade

npm i https://pkg.pr.new/trpc/trpc/@trpc/upgrade@6602

commit: 83962fc

@KATT KATT added the 👋 free for all Feel free to pick this up and fix it if you want label Mar 15, 2025
@KATT KATT merged commit 16e52eb into next Mar 15, 2025
71 of 72 checks passed
@KATT KATT deleted the issues/6599 branch March 15, 2025 10:59
@github-actions
Copy link
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

👋 free for all Feel free to pick this up and fix it if you want

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Allow Falsy Cursor Values in Infinite Query

3 participants