Why autorun runs before unmounting a component? #3058
-
I have an issue with Demo: here Based on the demo:
So, the question is: why is autorun being fired here, during unmounting? 🤔 I know I can fix the issue by reading |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
autorun
/reaction
is completely unaware of the component and it's lifecycle. It simply runs at the end of outermostaction
(transaction) - the order is not exactly specified - meaning one reaction/autorun shouldn't depend on another. Here, you assume thatApp
(observer
) is invalidated and rendered beforeautorun
, which is not the case.Also the effect's disposer function has a low priority I think (?), so it will always run after any(Probably not, it would be a bit inconvinient)autorun
(not sure).It also means that autorun may not see correct props as mentioned here: mobxjs/mobx-react#772 (comment) (3rd paragraph)