swr icon indicating copy to clipboard operation
swr copied to clipboard

Silent error in getKey within useSWRInfinite

Open onlyanegg opened this issue 1 year ago • 2 comments

Bug report

Description / Observed Behavior

useSWRInfinite hides errors within getKey (at least on the first page load). The error in getKey seems to cause the fetcher not to run. Because the error is hidden, it's difficult to debug.

Expected Behavior

I expect it to raise or display the error

Repro Steps / Code Example

import useSWRInfinite from "swr/infinite";

useSWRInfinite(                    
  () => {                          
    throw new Error();             
  },                               
  () => fetch("http://example.com")
);                                 

Additional Context

[email protected]

onlyanegg avatar Aug 03 '22 20:08 onlyanegg

This I a feature name "Conditional Fetching", not a bug https://swr.vercel.app/docs/conditional-fetching. And why do you want to throw an error in getKey?

quantran020173 avatar Aug 09 '22 04:08 quantran020173

This isn't about conditional fetching; it's about hiding an error. I don't want to raise an error in the getKey function; this was a minimal example for reproduction. When there is an error in the getKey function, it's hidden which makes it difficult to debug. I'd like to either raise that error or log it.

onlyanegg avatar Aug 10 '22 14:08 onlyanegg