Recoil: Random "Can't perform a React state update on an unmounted component..." errors in v0.2.0.
After upgrading to version v0.2.0 I’m getting errors like this at random components and can’t figure out why it happens. All components works fine with v0.1.2. All my atoms just simple atoms without async selectors and other complicated stuff.
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
at node_modules\react-native\Libraries\LogBox\LogBox.js:173:8 in registerError
at node_modules\react-native\Libraries\LogBox\LogBox.js:59:8 in errorImpl
at node_modules\react-native\Libraries\LogBox\LogBox.js:33:4 in console.error
at node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:106:4 in printWarning
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:75:16 in error
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:19152:9 in warnAboutUpdateOnUnmountedFiberInDEV
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17093:40 in scheduleUpdateOnFiber
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:11003:16 in dispatchAction
at [native code]:null in dispatchAction
at node_modules\recoil\native\recoil.js:4309:24 in subscribeToRecoilValue$1$argument_2
at node_modules\recoil\native\recoil.js:3321:41 in sendEndOfBatchNotifications
at node_modules\recoil\native\recoil.js:3374:6 in Recoil_Queue.enqueueExecution$argument_1
at node_modules\recoil\native\recoil.js:1041:0 in enqueueExecution
at node_modules\recoil\native\recoil.js:3355:18 in useEffect$argument_0
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:15561:31 in commitHookEffectListMount
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:15618:35 in commitPassiveHookEffects
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:265:4 in invokeGuardedCallbackImpl
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:476:2 in invokeGuardedCallback
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18795:29 in flushPassiveEffectsImpl
at node_modules\scheduler\cjs\scheduler.development.js:653:23 in unstable_runWithPriority
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17650:21 in performSyncWorkOnRoot
at [native code]:null in performSyncWorkOnRoot
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5321:31 in runWithPriority$argument_1
at node_modules\scheduler\cjs\scheduler.development.js:653:23 in unstable_runWithPriority
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5316:21 in flushSyncCallbackQueueImpl
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5304:28 in flushSyncCallbackQueue
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17125:30 in scheduleUpdateOnFiber
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:11003:16 in dispatchAction
at [native code]:null in dispatchAction
at node_modules\recoil\native\recoil.js:3354:2 in Batcher
at node_modules\recoil\native\recoil.js:3556:4 in replaceState
at node_modules\recoil\native\recoil.js:775:9 in applyActionsToStore
at node_modules\recoil\native\recoil.js:798:9 in queueOrPerformStateUpdate
at node_modules\recoil\native\recoil.js:841:24 in setRecoilValue
at node_modules\recoil\native\recoil.js:4416:9 in useSetRecoilState
at node_modules\expo-image-manipulator\build\ImageManipulator.js:4:7 in manipulateAsync
at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
at node_modules\regenerator-runtime\runtime.js:293:29 in invoke
at node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
at node_modules\regenerator-runtime\runtime.js:154:27 in invoke
at node_modules\regenerator-runtime\runtime.js:164:18 in PromiseImpl.resolve.then$argument_0
at node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
at node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
at [native code]:null in flushedQueue
at [native code]:null in invokeCallbackAndReturnFlushedQueue
Environment
software | version |
---|---|
expo | 40.0.1 |
react | 17.0.2 |
react-native | 0.63.4 |
recoil | 0.2.0 |
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 16
- Comments: 49 (5 by maintainers)
Commits related to this issue
- refactor: :recycle: beerTypes, countries selector 제거 -> useQuery를 감싼 커스텀 훅으로 리팩토링 recoil selector로 구현시 "Can't perform a React state update on an unmounted component..."에러 발생 https://github.com/facebo... — committed to depromeet/sulsul-FE by syoung125 2 years ago
- feat: 맥주 필터 기능 리팩토링 및 필터 url에 반영 (#84) * refactor: :truck: 폴더명 변경 filter -> beer-filter * chore: 미등록 맥주 기록하기 버튼 제거 및 맥주 등록 요청하기 onClick 구현 * feat: :alien: 반환타입 변경 대응 * refactor: :truck: Beer... — committed to depromeet/sulsul-FE by syoung125 2 years ago
Ok, I wrote a real quick Code Sandbox that illustrates the problem.
Here is the link to the Code Sandbox
https://codesandbox.io/s/recoil-breaking-hxmnj?file=/src/App.js
Just incase the link doesn’t work here is the main App.js with the problem.
To get the issue to appear. Click on “Click To Change Page”. Then click on the “Page 2” div. Since the recoil State was already on Page 1, but now it unmounted it will still fire and cause the issue.
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
Also I only see this if react is 16.X
Was having this and couldn’t figure out why. Finally tracked it down to a component that needed to be wrapped in
<Suspense>
(because of a nested async atom) but was not. I don’t know if there’s a way to improve the error message when that happens on the Recoil/React end, but if so it would be greatly appreciated because it was a huge pain to debug.This reproduces the warning in React, and I checked v0.1.3 doesn’t. Using
useSetRecoilState
instead ofuseRecoilState
prevents the warning (obviously?).One thing I noticed is, the first step change (
one
->two
) makes no warning, but the second one (two -> one
) shows the warning and the third (one
->two
), and no more warning after.Does not seem correct.
First of all the [setState] should be [state], not setState. setState is the function which sets the state, the state itself you call ‘state’. useEffect is looking for an array of values which might change and when they change the useEffect gets called.
The setState should just be setState(obj) or whatever you are setting the state to…
It’s not redux, you don’t pass a function in…
Reading the thread there seems to be two separate - but potentially related issues.
Would be helpful if someone with more knowledge than me helped in summarize as this issue is quickly growing in size with several examples and sandboxes that show the issue in different setting.
Seems like a huge problem potentially, Hope there’s a way to fix this…
I don’t have any async atom but I still get the issue. @GimpMaster could repro the issue here without async: https://codesandbox.io/s/recoil-breaking-hxmnj?file=/src/App.js
React has removed this warning, please see this discussion about it
@Svarto React 16 DOM here
Having the same issue with the latest 0.4.0 version. 😞
Repro this in react16 + recoil@0.2.0. I traced a little and found that in my scenario its related to
subscription.release
not called in this path , but i dont know whether its designed this way.@davwheat - Yeah I really think its a regression Recoil has with React 16.X
Just wanted to comment that I am seeing this issue too. I have a custom page router. I reduced my page down to just the useRecoilState with a return null.
When I switch to that page (which is now empty) and then to a different page and make a change to the same atom used on both pages I’ll get errors that were mentioned above.
I’m currently using React “16.13.1”
This just started happening after upgrading to Recoil 0.2.0
I made this demo but without errors
https://snack.expo.io/@amstko/react-native-recoil
In this example: no problem. In my stack with a more complexe code: “Can’t perform a React state update on an unmounted component…” He try to update value from useRecoilValue on the unmounted screen
I’ll investigate my code for see differences but I have 3 sub level of navigation with a lot of components.
Don’t hesitate to take my demo and make your one ✌️
Also I have this error in React Native console for this problem
Hey @cyphire ! I use useSetRecoilState in a function after an onPress by the user. Not in the useEffect hook. I can live with his erros for now and I’m crossing my fingers for a resolution with react 17 that will come within 3 months in Expo
Just want to add, this is also happening to us in React (so not just react-native). Can’t provide any code as the error is too generic but it appears to be related to components unmounting.