-
Notifications
You must be signed in to change notification settings - Fork 53
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
feat(react): prevent recursive exposing fallback when fallback throw error #1409
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: be9e879 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
People can be co-author:
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Size Change: +273 B (+0.4%) Total Size: 69.2 kB
ℹ️ View Unchanged
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1409 +/- ##
==========================================
+ Coverage 73.89% 74.20% +0.30%
==========================================
Files 70 70
Lines 590 597 +7
Branches 131 132 +1
==========================================
+ Hits 436 443 +7
Misses 142 142
Partials 12 12
|
Co-authored-by: Lee HyunJae (whale) <[email protected]>
Co-authored-by: lucas0530 <[email protected]>
Co-authored-by: HYUNGU KANG <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this change. It aligns with the same mechanism used by React Suspense, react-error-boundary (both propagate issues to the parent when a problem occurs in the fallback).
However, I’m concerned that this change could significantly impact existing users. I believe it qualifies as a breaking change, as updating might result in different behavior for previous users.
Additionally, looking at it differently, I think a looping fallback could be an optional feature. Why must errors within a fallback propagate to the parent fallback? What if this behavior were made configurable(options)? (this is just my opinion.)
Hi, I'm a big fan of Suspensive. I have a suggestion 🙌 @manudeli I wish because I want to see the After reading the react-query docs | useSuspenseQuery, I made a component like this. (before I saw this PR) interface Props {
isFetching: boolean;
error: Error | null;
children: React.ReactNode;
}
export default function ThrowError({ isFetching, error, children }: Props) {
if (error && !isFetching) {
throw error;
}
return <>{children}</>;
} <SuspenseQuery {...itemsQueryOptions()}>
{({ data: items , isFetching, error }) => (
<ThrowError isFetching={isFetching} error={error}>
<QueryClientConsumer>
{queryClient => (
<>
{items.map(item => (
<ItemCard
key={item.id}
item={item}
onClick={() => {
queryClient.invalidateQueries(itemsQueryOptions());
}}
/>
))}
</>
)}
</QueryClientConsumer>
</ThrowError>
)}
</SuspenseQuery> I think I hope the The link below is a website that has an API error with a 50% probability. When you click on the card, https://suspensive-ex.vercel.app |
🚧 This PR could make a huge difference, so please help us make sure this change gets a very thorough review. 🚧
Problem: ErrorBoundary's fallback can't be treated by parent ErrorBoundary
Thrown Error in fallback will be caught by ErrorBoundary self and then expose fallback recursively 🥲
Solution: When we meet thrown error in fallback of ErrorBoundary wrap it as InternalFallbackError, re-throw InternalFallbackError.fallbackError, if it is InternalFallbackError
Thrown Error in fallback will be caught by parent ErrorBoundary 👍
PR Checklist