Skip to content

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

@0xoizys

Description

@0xoizys

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions