You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.
Describe the bug
The Get component has an abort handler that will cancel any state updates after the component umounts. However, since the fetch call is wrapped in a try catch block, it will bypass the abort check and update state resulting in the classic Warning: Can't perform a React state update on an unmounted component
This is because the abort check is after the catch block intercepts the error thrown by fetch
Call an API that will result in an error such as 401, 404, etc
Unmount the component before the call finishes and the error is thrown
Expected behavior
The state should not be updated when the component is unmounted, regardless of whether there is an error or not
Additional context
I would open a PR for this issue myself but I am unable to reliably reproduce the issue in a unit test (as setState on unmounted components are fairly hard to test)
The text was updated successfully, but these errors were encountered:
Describe the bug
The
Get
component has an abort handler that will cancel any state updates after the component umounts. However, since the fetch call is wrapped in a try catch block, it will bypass the abort check and update state resulting in the classicWarning: Can't perform a React state update on an unmounted component
This is because the abort check is after the catch block intercepts the error thrown by
fetch
restful-react/src/Get.tsx
Lines 256 to 262 in 529bdb3
I was able to fix this issue by putting the abort check in the catch block as well
https://github.com/AJHenry/restful-react/blob/8627e00f58cfc8c69d050c0d9a811717aa6e0533/src/Get.tsx#L381-L385
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The state should not be updated when the component is unmounted, regardless of whether there is an error or not
Additional context
I would open a PR for this issue myself but I am unable to reliably reproduce the issue in a unit test (as
setState
on unmounted components are fairly hard to test)The text was updated successfully, but these errors were encountered: