Aborting action with AbortController does not work immediately, causes trouble with React.StrictMode #1987
Labels
bug
Confirmed bug
help/PR welcome
Help/Pull request from contributors to fix the issue is welcome
level: intermediate
Bug report
Sandbox link or minimal reproduction code
Here is the reproduction codesandbox: https://codesandbox.io/s/mobx-state-tree-abort-bug-irs5ch?file=/src/App.js
Describe the expected behavior
I expect that aborting the promise (with AbortController) should cause flow to end the action and run the catch block before starting a new action. This race condition happens because React StrictMode will render every component twice. Since I start store actions in useEffect, I want to run a cleanup action when unmounting, so the component is ready for the next run.
Describe the observed behavior
The catch block is ran a while later, not sure exactly when, but it ends up causing the second action to run before the first one finishes. Notice that if you disable React StrictMode it works ok.
Also, the documentation for mobx mentions being able to cancel flow actions here: https://mobx.js.org/actions.html#cancelling-flows-. But this is not available for the flow in mobx-state-tree right?
The text was updated successfully, but these errors were encountered: