swr icon indicating copy to clipboard operation
swr copied to clipboard

When Suspense is enabled, error thrown inside fetcher function is not thrown by SWR (swallowed)

Open 0xoizys opened this issue 3 years ago • 3 comments

Bug report

Description / Observed Behavior

Suspense is enabled when calling useSWR, and an error is thrown inside the fetcher function when attempting to fetch.

The error isn't being re-thrown by SWR, or reported as an uncaught error, and I am unable to handle it in an Error Boundary.

Expected Behavior

I would expect SWR to re-throw the error thrown in the fetcher function, and for me to be able to handle it with an Error Boundary, or for it to be reported as an uncaught error.

Instead, the error is not surfaced by SWR and is "swallowed".

Repro Steps / Code Example

https://codesandbox.io/s/silly-cookies-igxf7b?file=/pages/index.tsx

Additional Context

SWR version: 2.0.0-rc Nextjs version: 12.3.2-canary Suspense is enabled

0xoizys avatar Oct 14 '22 16:10 0xoizys

That's because you're passing the fallbackData option. Remove that and it'll work.

blackmann avatar Oct 15 '22 08:10 blackmann

That's because you're passing the fallbackData option. Remove that and it'll work.

oh hmm, does fallbackData also apply for client fetches, or just during server rendering? i'm triggering a fetch from the client in the example and still not seeing the error surface

(and in version 2.0.0-rc of SWR it seems that the fallbackData prop is required if the hook gets rendered in the server)

0xoizys avatar Oct 15 '22 16:10 0xoizys

Same for me:

image

imclint21 avatar Nov 11 '22 20:11 imclint21