-
Notifications
You must be signed in to change notification settings - Fork 305
fix(error-boundary): remove ErrorBoundaryGroup's not on purpose reset because of isMounted's side effect #287
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
fix(error-boundary): remove ErrorBoundaryGroup's not on purpose reset because of isMounted's side effect #287
Conversation
… because of isMounted's side effect
👷 Deploy request for slash-libraries pending review.Visit the deploys page to approve it
|
@@ -51,7 +51,6 @@ const initialState: ErrorBoundaryState = { | |||
|
|||
class BaseErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> { | |||
state = initialState; | |||
updatedWithError = false; |
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 thought this BaseErrorBoundary.updatedWithError
is unnecessary field, there is no updatedWithError in https://github.com/bvaughn/react-error-boundary/blob/master/src/ErrorBoundary.ts too.
If this is matter, let me know why meaningful please.
resetState() { | ||
this.updatedWithError = false; | ||
this.setState(initialState); | ||
} | ||
|
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 remove this method BaseErrorBoundary.resetState
. if no updatedWithError field, resetState is not anymore meaningful too.
I thought this.setState(initialState)
is better to express what this is.
/** @tossdocs-ignore */ | ||
import { usePrevious } from '@toss/react'; | ||
|
||
export const useIsChanged = (value: unknown) => usePrevious(value) !== value; |
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 made custom hook, useIsChanged
to check whether value is changed with previous rendering value.
this hook will check parent ErrorBoundaryGroup.resetKey is changed
If parentErrorBoundaryGroup.resetKey is changed, ErrorBoundaryGroup self will change resetkey to propagate to child ErrorBoundaryGroup recursively.
…unnecessary-rerender
…unnecessary-rerender
…unnecessary-rerender
…unnecessary-rerender
…unnecessary-rerender
…unnecessary-rerender
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.
LGTM👍🚀
…unnecessary-rerender
…unnecessary-rerender
…unnecessary-rerender
@manudeli is attempting to deploy a commit to the Toss Team on Vercel. A member of the Team first needs to authorize it. |
…unnecessary-rerender
related with toss/suspensive#92
Remove ErrorBoundaryGroup's not on purpose reset because of isMounted's side effect
useIsMounted of @toss/react is implemented by useState, but we don't need to use useIsMounted triggering rerender component self when after mount.
useIsMounted
of @toss/reactbefore this Pull Request, ErrorBoundaryGroup used useIsMounted to prevent reseting ErrorBoundaryGroup self on first rendering, and after mounting and checked whether parent ErrorBoundaryGroup.resetKey is changed to reset self.
but after this Pull Request is merging, we don't need to make unnecessary rerendering due to useIsMounted.
In addition, we can prevent unintended ErrorBoundaryGroup resetting by useIsMounted.
When first I add this ErrorBoundaryGroup in @toss/error-boundary, I couldn't consider useIsMounted's rerendering side effect
AS-IS
ErrorBoundaryGroup will trigger reset on render because of useIsMounted
TO-BE
ErrorBoundaryGroup won't trigger reset on render because of removed useIsMounted
Check more detail and procedure to add this Pull Request in toss/suspensive#92 please
PR Checklist