Skip to content

useSWRInfinite hook returns incorrect data on versions >= 2.3.0 #4170

@giantslogik

Description

@giantslogik

Bug report

I upgraded from 2.2.5 to 2.3.6.
I've tested older versions to determine this broke with 2.3.0

Description / Observed Behavior

For simplicity i'm describing the case where the backend returns an empty page.
with >= 2.3.0 the data returned from useSwrInfinite is [null]. The custom fetcher is not invoked. Before the upgrade this used to return undefined as an initial value.

The incorrect data crashes my app.

Expected Behavior

With 2.2.25 the data is: [{"totalCount":0,"data":[]}] . This is returned by the backend webservice call. (data property is not data property of useSWRInfinite. )

Repro Steps / Code Example

interface ResponseProtocol {
  data: Array<unknown>;
  statusCode?: number;
};

  const {
    data, // This is incorrect with >=2.3.0
    mutate,
    setSize,
    isValidating,
    isLoading,
    error: rawError
  } = 
useSWRInfinite<ResponseProtocol>(getKey, {
    refreshInterval: pollingInterval,
    onSuccess: undefined,
    compare: dequal,// https://www.npmjs.com/package/dequal
    fallbackData: undefined
  });

Additional Context

SWR version.
2.3.0 to 2.3.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions