Skip to content

SWR: useSWRInfinite implementation doesn't support pagination parameters #2106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tk1024 opened this issue May 22, 2025 · 1 comment
Open
Labels
swr SWR related issues

Comments

@tk1024
Copy link

tk1024 commented May 22, 2025

Description

The current SWR integration in Orval doesn't properly support useSWRInfinite pagination. The generated swrKeyLoader function doesn't accept the required pageIndex and previousPageData parameters that SWR Infinite expects, making infinite pagination impossible to implement.

Expected Behavior

The generated swrKeyLoader should:

  1. Accept pageIndex and previousPageData parameters from useSWRInfinite
  2. Pass these parameters to the underlying key loader function
  3. Enable proper infinite pagination functionality

Current Behavior

The generated code creates a swrKeyLoader that doesn't accept any parameters:

const swrKeyLoader = swrOptions?.swrKeyLoader ?? (() => isEnabled ? getOperationInfiniteKeyLoader(params) : null);

This prevents useSWRInfinite from working correctly because it can't pass pagination parameters to determine the next page key.

Steps to Reproduce

  1. Configure Orval to generate SWR hooks with useInfinite: true
  2. Try to use the generated infinite hook
  3. Notice that pagination doesn't work because pageIndex and previousPageData are not available

Proposed Solution

The swrKeyLoader should be generated as:

const swrKeyLoader = swrOptions?.swrKeyLoader ?? ((pageIndex, previousPageData) => isEnabled ? getOperationInfiniteKeyLoader(params)(pageIndex, previousPageData) : null);
const swrFn = ([_url, params]) => operationName(params);

Environment

  • Orval version: 7.9.0
  • SWR version: Latest
  • TypeScript version: Latest
@tk1024
Copy link
Author

tk1024 commented May 22, 2025

I tried a simple fix, but couldn't make it type-safe.

tk1024@7cf100e

@melloware melloware added the swr SWR related issues label May 22, 2025
@melloware melloware changed the title useSWRInfinite implementation doesn't support pagination parameters SWR: useSWRInfinite implementation doesn't support pagination parameters May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
swr SWR related issues
Projects
None yet
Development

No branches or pull requests

2 participants