#2771·swr

Bug in `createCacheHelper`

Author: ghostCreated Sep 5, 2023Updated May 19, 2026
Labelsreproduction needed

Bug report

I am using useInfiniteSWR in a react SDK I have built. Everything works as expected in the development server. But when I use the production build of the SDK I am getting the following error

txt
TypeError: Cannot read properties of undefined (reading '6')
    at Ye (index.es.js:6095:1)
    at eval (index.es.js:6468:1)
    at useSWRArgs (index.mjs:642:1)
    # other lines....

I dug deeper into this and found out that the infinite middleware in 'swr/infinite' library file uses createCacheHelper function. This function returns an array of 4 objects, of which the third object is a subscriber. This subscriber comes from state[6] where state is obtained from SWRGlobalState.get(cache).

The cache here is passed into the createCacheHelper as the first argument by the infinite middleware.

Description / Observed Behavior

This is causing my app to crash.

Expected Behavior

App should not crash.

Additional Context

SWR version - 2.2.2

Screenshot 2023-09-05 at 4 04 17 PMcreateCacheHelper fileswr/infinite file