Skip to content

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

@tk1024

Description

@tk1024

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

Metadata

Metadata

Assignees

Labels

swrSWR related issues

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions