Skip to content

Conversation

@visz11
Copy link
Collaborator

@visz11 visz11 commented Dec 15, 2025

CodeAnt-AI Description

Allow explicit pageParam when fetching infinite query pages

What Changed

  • fetchNextPage and fetchPreviousPage now accept and forward an explicit pageParam so the query function receives the provided cursor when loading the next/previous page
  • Refetch uses previously provided manual pageParam values so pages fetched imperatively are preserved on refetch
  • getNextPageParam is now optional and TypeScript signatures require callers to pass pageParam for next/previous fetches when getNextPageParam is not provided; tests added to validate behavior

Impact

✅ Clearer infinite pagination control when using manual cursors
✅ Fewer unexpected page param derivations during imperative fetches
✅ Stronger TypeScript guarantees for manual vs automatic paging

💡 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.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

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

    • fetchNextPage and fetchPreviousPage now accept an optional pageParam parameter to explicitly control pagination behavior.
    • getNextPageParam configuration is now optional, providing more flexibility in infinite query setups.
  • Tests

    • Added test coverage for pageParam usage in infinite query pagination.
    • Added TypeScript type validation tests for pagination methods.

✏️ Tip: You can customize this high-level summary in your review settings.

let's bring back imperative infinite queries, but only allow them in an all-or-nothing mode, dependent on if `getNextPageParam` has been passed
@codeant-ai
Copy link

codeant-ai bot commented Dec 15, 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

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai
Copy link

coderabbitai bot commented Dec 15, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This pull request enhances infinite query pagination by adding support for explicit pageParam overrides in fetchNextPage and fetchPreviousPage methods, making the getNextPageParam option optional in the type system, and propagating pageParam metadata through the query pipeline. The changes maintain backward compatibility while enabling callers to override page parameters when fetching additional pages.

Changes

Cohort / File(s) Summary
Test additions
packages/query-core/src/__tests__/infiniteQueryBehavior.test.tsx, packages/query-core/src/__tests__/infiniteQueryObserver.test-d.tsx
New test cases for pageParam behavior and type-checking tests for InfiniteQueryObserver with and without getNextPageParam defined. Includes validation of fetchNextPage and fetchPreviousPage parameter acceptance under different configurations.
Observer method signatures
packages/query-core/src/infiniteQueryObserver.ts
fetchNextPage and fetchPreviousPage updated to accept destructured parameters including optional pageParam; both methods now propagate pageParam via meta.fetchMore alongside direction.
Behavior logic updates
packages/query-core/src/infiniteQueryBehavior.ts
Added explicit pageParam override support with fallback to existing pageParam derivation. Replaced optional chaining for getNextPageParam and getPreviousPageParam function calls to handle optional configurations. Updated fetch-all-pages logic to consider initialPageParam or first-page pageParam when getNextPageParam is unavailable.
Type system changes
packages/query-core/src/types.ts
Made getNextPageParam optional in InfiniteQueryPageParamsOptions interface.
Metadata type expansion
packages/query-core/src/query.ts
Extended FetchMeta.fetchMore type to include optional pageParam?: unknown field alongside direction.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Areas requiring extra attention:

  • infiniteQueryBehavior.ts: Logic changes for explicit pageParam override and optional chaining behavior; verify fallback logic handles all edge cases
  • infiniteQueryObserver.ts: Method signature changes propagating pageParam through meta; ensure backward compatibility with existing callers
  • types.ts: Making getNextPageParam optional may alter type inference and hasNextPage determination; verify implications across consumers
  • Test coverage: Verify duplication in infiniteQueryBehavior.test.tsx is intentional

Poem

🐰 Hop along with pageParam, now,
No more tripping on param-less bow,
Optional cursors, metadata flows,
The query dance simply grows and grows! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ⚠️ Warning The pull request has no description; the template requires changes description and a checklist. Add a pull request description following the template. Describe what changes are made, why, and confirm testing and changeset generation.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Clone feature/imperative infinite queries' clearly summarizes the main change, which is implementing imperative infinite query pagination with explicit pageParam support.
✨ 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-feature/imperative-infinite-queries

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.

@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 feature that allows developers to imperatively specify the pageParam when fetching subsequent pages in an infinite query. This enhances flexibility by enabling direct control over the page parameter, moving beyond the previous reliance on getNextPageParam and getPreviousPageParam functions. It also makes the getNextPageParam option itself optional, supporting a fully imperative approach to infinite query pagination.

Highlights

  • Imperative PageParam Control: The fetchNextPage and fetchPreviousPage methods now accept an optional pageParam directly in their options, allowing for manual control over pagination.
  • Optional getNextPageParam: The getNextPageParam option in InfiniteQueryPageParamsOptions is now optional, enabling infinite queries to be defined without it if pageParam is always provided imperatively.
  • Enhanced Type Safety: New type tests have been added to ensure that pageParam is correctly allowed or required on fetchNextPage/fetchPreviousPage based on whether getNextPageParam is defined.
  • Refetch Behavior with Manual PageParams: The system now correctly re-uses manually provided pageParam values when performing a refetch operation, maintaining consistency.
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.

@visz11
Copy link
Collaborator Author

visz11 commented Dec 15, 2025

@refacto-visz

@codeant-ai codeant-ai bot added the size:L This PR changes 100-499 lines, ignoring generated files label Dec 15, 2025
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 significant new feature: imperative fetching for infinite queries. This allows developers to manually specify pageParam when calling fetchNextPage or fetchPreviousPage, which is useful when automatic page param detection via getNextPageParam is not suitable. The changes span across core logic, types, and tests to support this new capability.

My review identifies a potential bug in the refetch logic for these new imperative queries which could lead to incorrect data being fetched. I've also included suggestions to improve the developer experience by adding development-mode warnings for incorrect usage of the new imperative API, which currently fails silently.

Comment on lines 102 to 105
const param =
currentPage === 0
? (oldPageParams[0] ?? options.initialPageParam)
currentPage === 0 || !options.getNextPageParam
? (oldPageParams[currentPage] ?? options.initialPageParam)
: getNextPageParam(options, result)

Choose a reason for hiding this comment

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

high

The current logic for determining the param for refetching has a potential bug. When !options.getNextPageParam is true, the expression oldPageParams[currentPage] ?? options.initialPageParam is used for all pages. This is incorrect for pages other than the first one (currentPage > 0). If oldPageParams[currentPage] is undefined for some reason, it will incorrectly fall back to options.initialPageParam, which could lead to fetching the wrong page data during a refetch.

The fallback to initialPageParam should only apply to the very first page (currentPage === 0). For subsequent pages in manual mode, we should rely on oldPageParams[currentPage] exclusively. I've suggested a refactor of this logic to make it safer and more explicit.

            const param =
              currentPage === 0
                ? oldPageParams[0] ?? options.initialPageParam
                : !options.getNextPageParam
                ? oldPageParams[currentPage]
                : getNextPageParam(options, result)

Comment on lines +127 to 136
fetchNextPage({ pageParam, ...options }: FetchNextPageOptions = {}): Promise<
InfiniteQueryObserverResult<TData, TError>
> {
return this.fetch({
...options,
meta: {
fetchMore: { direction: 'forward' },
fetchMore: { direction: 'forward', pageParam },
},
})
}

Choose a reason for hiding this comment

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

medium

When getNextPageParam is not defined, fetchNextPage must be called with a pageParam. Currently, if it's called without one (e.g., fetchNextPage()), it results in a silent no-op. This can be confusing and hard to debug.

To improve the developer experience, I suggest adding a check that logs an error in development mode if fetchNextPage is called without a pageParam when getNextPageParam is not provided. This will make the API usage clearer and prevent silent failures.

  fetchNextPage({ pageParam, ...options }: FetchNextPageOptions = {}): Promise<
    InfiniteQueryObserverResult<TData, TError>
  > {
    if (
      process.env.NODE_ENV !== 'production' &&
      pageParam === undefined &&
      !this.options.getNextPageParam
    ) {
      console.error(
        `'pageParam' is required for 'fetchNextPage' when 'getNextPageParam' is not defined.`,
      )
    }
    return this.fetch({
      ...options,
      meta: {
        fetchMore: { direction: 'forward', pageParam },
      },
    })
  }

Comment on lines +138 to 150
fetchPreviousPage({
pageParam,
...options
}: FetchPreviousPageOptions = {}): Promise<
InfiniteQueryObserverResult<TData, TError>
> {
return this.fetch({
...options,
meta: {
fetchMore: { direction: 'backward' },
fetchMore: { direction: 'backward', pageParam },
},
})
}

Choose a reason for hiding this comment

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

medium

Similar to fetchNextPage, fetchPreviousPage will fail silently if called without a pageParam when getPreviousPageParam is not defined. This can lead to a poor developer experience.

I recommend adding a development-mode warning to alert the user when they call fetchPreviousPage without the required pageParam in manual pagination mode. This will help catch configuration errors early.

  fetchPreviousPage({
    pageParam,
    ...options
  }: FetchPreviousPageOptions = {}): Promise<
    InfiniteQueryObserverResult<TData, TError>
  > {
    if (
      process.env.NODE_ENV !== 'production' &&
      pageParam === undefined &&
      !this.options.getPreviousPageParam
    ) {
      console.error(
        `'pageParam' is required for 'fetchPreviousPage' when 'getPreviousPageParam' is not defined.`,
      )
    }
    return this.fetch({
      ...options,
      meta: {
        fetchMore: { direction: 'backward', pageParam },
      },
    })
  }

@visz11 visz11 closed this Dec 15, 2025
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: 1

♻️ Duplicate comments (1)
packages/query-core/src/infiniteQueryObserver.ts (1)

138-148: Same type issue applies to FetchPreviousPageOptions

fetchPreviousPage uses the same { pageParam, ...options }: FetchPreviousPageOptions = {} pattern, so it’s affected by the same missing pageParam property on FetchPreviousPageOptions. Once you add pageParam?: … to both option interfaces in packages/query-core/src/types.ts (as suggested above), this method’s typing will be consistent with its implementation.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f15b7fc and 644677e.

📒 Files selected for processing (6)
  • packages/query-core/src/__tests__/infiniteQueryBehavior.test.tsx (1 hunks)
  • packages/query-core/src/__tests__/infiniteQueryObserver.test-d.tsx (1 hunks)
  • packages/query-core/src/infiniteQueryBehavior.ts (4 hunks)
  • packages/query-core/src/infiniteQueryObserver.ts (1 hunks)
  • packages/query-core/src/query.ts (1 hunks)
  • packages/query-core/src/types.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/query-core/src/__tests__/infiniteQueryObserver.test-d.tsx (1)
packages/query-core/src/infiniteQueryObserver.ts (1)
  • InfiniteQueryObserver (27-198)
packages/query-core/src/__tests__/infiniteQueryBehavior.test.tsx (4)
packages/query-core/src/__tests__/utils.ts (1)
  • queryKey (24-27)
packages/query-core/src/queriesObserver.ts (2)
  • observer (255-261)
  • result (185-202)
packages/query-core/src/infiniteQueryObserver.ts (1)
  • InfiniteQueryObserver (27-198)
packages/query-core/src/types.ts (1)
  • InfiniteQueryObserverResult (1049-1057)
packages/query-core/src/infiniteQueryObserver.ts (1)
packages/query-core/src/types.ts (3)
  • FetchNextPageOptions (586-596)
  • InfiniteQueryObserverResult (1049-1057)
  • FetchPreviousPageOptions (598-608)
🪛 GitHub Actions: pr
packages/query-core/src/infiniteQueryObserver.ts

[error] 122-122: TS2339: Property 'pageParam' does not exist on type 'FetchNextPageOptions'.

🔇 Additional comments (8)
packages/query-core/src/query.ts (1)

91-93: LGTM!

The addition of an optional pageParam?: unknown to FetchMeta.fetchMore correctly enables passing explicit page parameters through the fetch pipeline while maintaining backward compatibility.

packages/query-core/src/__tests__/infiniteQueryBehavior.test.tsx (1)

204-306: LGTM!

This test comprehensively validates the new pageParam override feature:

  • Tests explicit pageParam in both fetchNextPage and fetchPreviousPage
  • Verifies that refetch correctly uses the stored pageParams from previous manual fetches
  • Properly cleans up the subscription
packages/query-core/src/types.ts (1)

274-274: Making getNextPageParam optional enables imperative pagination.

This change allows users to omit getNextPageParam and instead provide pageParam explicitly when calling fetchNextPage/fetchPreviousPage.

Note: When getNextPageParam is undefined, hasNextPage will always return false (see infiniteQueryBehavior.ts:168). This is likely intentional since automatic next-page detection isn't possible without the callback.

Please confirm this is the intended behavior for hasNextPage when using imperative pagination without getNextPageParam.

packages/query-core/src/__tests__/infiniteQueryObserver.test-d.tsx (2)

76-95: Type test validates pageParam exclusion when getNextPageParam is defined.

This correctly enforces that when automatic pagination is configured via getNextPageParam, the pageParam option should not be available, preventing accidental override of the derived page parameter.


97-117: The type test expectations indicate that FetchNextPageOptions and FetchPreviousPageOptions need conditional typing based on getNextPageParam presence.

The test expects pageParam to be conditionally required when getNextPageParam is missing and conditionally forbidden when getNextPageParam is defined. However, the current FetchNextPageOptions and FetchPreviousPageOptions interfaces (types.ts lines 586-608) are static and don't include pageParam at all, nor do they have conditional properties based on query options.

The runtime methods destructure pageParam from options, but the types don't reflect this capability. The type definitions need to be updated to support conditional pageParam based on whether getNextPageParam is provided in the observer configuration.

packages/query-core/src/infiniteQueryBehavior.ts (3)

84-96: LGTM!

The updated logic correctly handles:

  1. Explicit pageParam override from fetchMore.pageParam when provided
  2. Fallback to pageParamFn when pageParam is undefined

This distinction allows callers to explicitly pass null to stop pagination (handled by line 53's param == null check).


102-111: Good fallback for missing getNextPageParam.

When getNextPageParam is undefined, the code correctly falls back to stored oldPageParams or initialPageParam, enabling refetch of previously fetched pages even without automatic page parameter derivation.


136-149: Optional chaining aligns with updated type definitions.

Using options.getNextPageParam?.(...) correctly handles the case where getNextPageParam is now optional in InfiniteQueryPageParamsOptions.

Comment on lines +127 to 134
fetchNextPage({ pageParam, ...options }: FetchNextPageOptions = {}): Promise<
InfiniteQueryObserverResult<TData, TError>
> {
return this.fetch({
...options,
meta: {
fetchMore: { direction: 'forward' },
fetchMore: { direction: 'forward', pageParam },
},
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, locate and examine infiniteQueryObserver.ts around the specified lines
fd infiniteQueryObserver.ts --type f

Repository: coderabbit-test/query

Length of output: 113


🏁 Script executed:

# Also find types.ts in the same directory structure
fd types.ts packages/query-core/src

Repository: coderabbit-test/query

Length of output: 97


🏁 Script executed:

# Once found, let me check the exact content of infiniteQueryObserver.ts at lines 127-148
cat -n packages/query-core/src/infiniteQueryObserver.ts | sed -n '120,150p'

Repository: coderabbit-test/query

Length of output: 993


🏁 Script executed:

# Now check the types.ts file for FetchNextPageOptions and FetchPreviousPageOptions
cat -n packages/query-core/src/types.ts | grep -A 20 "FetchNextPageOptions\|FetchPreviousPageOptions"

Repository: coderabbit-test/query

Length of output: 2604


🏁 Script executed:

# Verify there are no other uses of pageParam in FetchNextPageOptions or related types
rg "pageParam" packages/query-core/src/types.ts

Repository: coderabbit-test/query

Length of output: 306


🏁 Script executed:

# Check if there are any imports or extensions that might add pageParam to these interfaces
rg "FetchNextPageOptions\|FetchPreviousPageOptions" packages/query-core/src/types.ts | head -20

Repository: coderabbit-test/query

Length of output: 47


🏁 Script executed:

# Let me check the full context around where pageParam appears in types.ts
rg -B 5 -A 5 "pageParam" packages/query-core/src/types.ts | head -100

Repository: coderabbit-test/query

Length of output: 931


🏁 Script executed:

# Check if the interfaces have been updated - get more context around lines 586-608
cat -n packages/query-core/src/types.ts | sed -n '580,620p'

Repository: coderabbit-test/query

Length of output: 1829


🏁 Script executed:

# Check if there's a tsconfig.json or build configuration that might suppress these errors
find packages/query-core -name "tsconfig.json" -o -name "tsconfig.*.json" | head -5

Repository: coderabbit-test/query

Length of output: 178


🏁 Script executed:

# Let me verify the actual method signature once more and check if there are any type assertions or other overloads
rg -B 10 -A 10 "fetchNextPage\(" packages/query-core/src/infiniteQueryObserver.ts | head -40

Repository: coderabbit-test/query

Length of output: 566


🏁 Script executed:

# Check what ResultOptions contains
rg -B 5 -A 15 "interface ResultOptions" packages/query-core/src/types.ts

Repository: coderabbit-test/query

Length of output: 594


🏁 Script executed:

# Let me also search for any declaration merging or augmentation of FetchNextPageOptions
rg "FetchNextPageOptions" packages/query-core/src/ -A 5

Repository: coderabbit-test/query

Length of output: 2018


🏁 Script executed:

# Check the entire infiniteQueryObserver.ts file for any type definitions or overloads that might affect this
wc -l packages/query-core/src/infiniteQueryObserver.ts

Repository: coderabbit-test/query

Length of output: 117


🏁 Script executed:

# Check if there are any function overloads or declarations in the file
rg "fetchNextPage|fetchPreviousPage" packages/query-core/src/infiniteQueryObserver.ts -B 3

Repository: coderabbit-test/query

Length of output: 558


🏁 Script executed:

# Let's verify the exact line numbers and see if there are any decorators or type annotations that might bypass the type check
cat -n packages/query-core/src/infiniteQueryObserver.ts | sed -n '120,155p'

Repository: coderabbit-test/query

Length of output: 1107


🏁 Script executed:

# Let's check if the code actually compiles by looking for build errors or CI configuration
cat packages/query-core/tsconfig.json | head -50

Repository: coderabbit-test/query

Length of output: 285


🏁 Script executed:

# Check if there's a way the types could be different - let me search for any conditional types or generics that might make pageParam available
ast-grep --pattern 'export interface FetchNextPageOptions {
  $$$
}'

Repository: coderabbit-test/query

Length of output: 47


🏁 Script executed:

# Final verification: does TypeScript actually report an error? Let me check the complete method signature with full context
sed -n '127,136p' packages/query-core/src/infiniteQueryObserver.ts

Repository: coderabbit-test/query

Length of output: 329


Type mismatch: pageParam not declared on FetchNextPageOptions and FetchPreviousPageOptions

The methods destructure { pageParam, ...options } from FetchNextPageOptions and FetchPreviousPageOptions (lines 127–128 and 138–141), but neither interface declares a pageParam property. This causes a TypeScript TS2339 error and blocks compilation.

Add pageParam?: unknown to both interfaces in packages/query-core/src/types.ts:

export interface FetchNextPageOptions extends ResultOptions {
  /**
   * If set to `true`, calling `fetchNextPage` repeatedly will invoke `queryFn` every time,
   * whether the previous invocation has resolved or not. Also, the result from previous invocations will be ignored.
   *
   * If set to `false`, calling `fetchNextPage` repeatedly won't have any effect until the first invocation has resolved.
   *
   * Defaults to `true`.
   */
  cancelRefetch?: boolean
+  pageParam?: unknown
}

export interface FetchPreviousPageOptions extends ResultOptions {
  /**
   * If set to `true`, calling `fetchPreviousPage` repeatedly will invoke `queryFn` every time,
   * whether the previous invocation has resolved or not. Also, the result from previous invocations will be ignored.
   *
   * If set to `false`, calling `fetchPreviousPage` repeatedly won't have any effect until the first invocation has resolved.
   *
   * Defaults to `true`.
   */
  cancelRefetch?: boolean
+  pageParam?: unknown
}

If you need stronger typing, make the interfaces generic (e.g., FetchNextPageOptions<TPageParam>) and update the method signatures accordingly.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/query-core/src/infiniteQueryObserver.ts around lines 127 to 134 and
138 to 141, the methods destructure pageParam from
FetchNextPageOptions/FetchPreviousPageOptions but those interfaces lack a
pageParam property causing TS2339; fix by adding pageParam?: unknown to both
FetchNextPageOptions and FetchPreviousPageOptions in
packages/query-core/src/types.ts (or, if stronger typing is desired, convert
them to generic interfaces like FetchNextPageOptions<TPageParam> and
FetchPreviousPageOptions<TPageParam> and update the method signatures in
infiniteQueryObserver.ts to accept the corresponding generic type).

@codeant-ai
Copy link

codeant-ai bot commented Dec 15, 2025

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • fetchMore semantics changed
    The code now reads fetchMore from context.fetchOptions?.meta?.fetchMore and uses fetchMore.pageParam === undefined ? pageParamFn(...) : fetchMore.pageParam. This treats null as a valid explicit pageParam (different from undefined). Verify this behavioral change is intentional (should explicit null mean "use null" instead of computing the param?), and ensure callers that pass pageParam: null won't break pagination logic.

  • Meta overwritten
    The new implementations of fetchNextPage and fetchPreviousPage always replace the meta object with a new object that only contains fetchMore. If callers pass other meta properties (or an existing meta.fetchMore), those will be lost. This can cause unexpected behavior for callers that rely on additional meta fields.

  • Potential memory leak
    The getter added by addSignalProperty attaches a new abort event listener each time the signal property is accessed. If the query function or other code reads signal multiple times, this will register multiple listeners and may leak memory or cause multiple invocations of the same callback.

  • Cache / equality impact
    Adding pageParam may affect cache keys, fetch meta comparisons, and invalidation logic. Audit code paths that compare or serialize fetchMeta to ensure pageParam is included (or intentionally excluded). Also consider whether non-serializable page params (functions, DOM nodes) could cause unexpected behavior.

  • Type compatibility
    You added pageParam?: unknown to FetchMeta.fetchMore. Check all usages/types that consume FetchMeta (e.g. FetchOptions, FetchContext, behaviors, persister functions and any public APIs). Consumers that previously assumed only direction may need type updates or runtime handling for pageParam. Consider whether unknown is the right choice or if the type should be generic so callers can preserve the page param type.

@codeant-ai
Copy link

codeant-ai bot commented Dec 15, 2025

CodeAnt AI finished reviewing your PR.

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants