Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error not catched by onError using suspense #2239

Closed
imclint21 opened this issue Nov 11, 2022 · 4 comments · Fixed by #2658
Closed

Error not catched by onError using suspense #2239

imclint21 opened this issue Nov 11, 2022 · 4 comments · Fixed by #2658

Comments

@imclint21
Copy link

imclint21 commented Nov 11, 2022

Bug report

Description / Observed Behavior

I'm trying to use SWR with suspense, and the error (401 in my case) is not catched by onError when using suspense components.

Also I got a visual error like this:

Screenshot 2022-11-11 at 21 05 36

PS: I am using axios.

Expected Behavior

Retrieve the error in onError and not visually.

Repro Steps / Code Example

<ErrorBoundary fallback={<p>TEST</p>}>
	<Suspense fallback={<UserSummarySkeleton />}>
		<UserSummary />
	</Suspense>
</ErrorBoundary>
const { data: userSummary, error } = useSWR<UserSummary>(userId && `/v3/users/${userId}`, {
    suspense: true,
    fallback: {}
});

Additional Context

"next": "^13.0.3",
"swr": "^1.3.0",
"react-error-boundary": "^3.1.4",
@koba04
Copy link
Collaborator

koba04 commented Nov 12, 2022

@thisisclint21 could you reproduce this on CodeSandbox?

@mehm8128
Copy link

Hello, I encountered same issue.
I reproduced this issue on CodeSandbox, so please check it.
When you remove suspense: true from global settings, this become work correctly.
https://codesandbox.io/s/swr-state-forked-34iwp7?file=/src/Component.js

@brunubarbosa
Copy link

Coming across the same issue I found this in the Q&A section:
#747
It seems to be the expected behavior when using suspend

@BertrandBordage
Copy link

This is the same underlying issue as #1907.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants