Skip to content
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

Why am I getting an invalid action stack error? #2135

Closed
spark1031 opened this issue Oct 3, 2019 · 9 comments · Fixed by #2136
Closed

Why am I getting an invalid action stack error? #2135

spark1031 opened this issue Oct 3, 2019 · 9 comments · Fixed by #2136

Comments

@spark1031
Copy link

spark1031 commented Oct 3, 2019

Context:
I am trying to run some jest/react-testing-library tests with drone and get this error when the test tries to render my component.
Error message: "[mobx] invalid action stack. did you forget to finish an action?"
My component renders some data that is being loaded into a store via mobx. Every time this store is created, the load action is called inside the store's constructor. Every time this load action is called, the test fails. However, there are no errors that arise when I run my app and no errors that arise when I run my tests locally. This error only occurs when I run my tests in drone.

This error seems to originate from here:
https://github.com/mobxjs/mobx/blob/master/src/core/action.ts#L88
Which uses mobx globals which are defined here: https://github.com/mobxjs/mobx/blob/master/src/core/globalstate.ts#L157

  1. Looks like there is global state stacking for actions that are being run (and when they finish)
  2. Also looks like there are problems with the global state object if there are multiple versions on mobx active

Question:
What are some things I could try that could fix this issue? I tried looking on stackoverflow and had little luck finding others who had run into this issue :(

Hopefully someone can help me here!
Thank you in advance!

@Bnaya
Copy link
Member

Bnaya commented Oct 4, 2019

I would guess its related to #2117

@Bnaya
Copy link
Member

Bnaya commented Oct 4, 2019

Do you have multiple mobx versions?
Try:
https://mobx.js.org/refguide/api.html#isolateglobalstate-boolean

@ianmstew
Copy link

ianmstew commented Oct 4, 2019

I can confirm 2 separate instances of this error halting development at my firm, and we had to roll back to [email protected] until we could determine what is going wrong, whether that's on our side on or the framework side.

@xaviergonz, I am curious the reason for adding this severe of an error in a patch release. If the only reason is to support advanced (framework-level) use of startAction/endAction as discussed in the linked issue, then I would argue it should never break during any first class API usage and the risk of breakage isn't necessarily worth the niche upside for framework developers. If the reason is to catch misuse of first class API usage, then heads up that there are hard to debug edge cases out in the wild (including two separate apps in my firm), and we did not expect to land a dev-breaking debug-heavy issue on a patch version.

Re: https://github.com/mobxjs/mobx/pull/2117/files#diff-8406aeda76dceeb1a83b0a0392bba4ecR86

@xaviergonz
Copy link
Contributor

In theory that error (which I added as it was suggested to me here btw: #2117 (comment) ) should never happen when not using those functions directly, but it is true I didn't think of multiple mobx versions sharing the global state (where the new version would update the current action id and the other won't).

I'll create a patch that rather than reusing the global state will use their own local state, though it would be cool if somebody could produce a minimum reproduction code.

@mweststrate
Copy link
Member

@xaviergonz note that the globalversion object has a version number, that is intended to be used to remain backward compatible / it will warn if there are multiple version of mobx sharing incompatible versions of global state.

That being said @spark1031; having multiple versions is in most cases a sign of an incorrect package setup, so unless there is an explicit reason why you need multiple versions (the only case I know: having external parties writing plugins for your product that can have their own mobx), the best thing to do is to make sure you have only one version of mobx. It will make your bundle smaller as well.

Usually this is caused by using npm link, or by using dependencies that have mobx as dependency instead of as peer dependency.

@danielkcz
Copy link
Contributor

Yarn offers a good option to deduplicate different library versions. In package.json add, for example, following and all packages will be forced to use that version and there will be only one sitting at the root of node_modules.

"resolutions": {
  "mobx": "5.14.0"
}

@Bnaya
Copy link
Member

Bnaya commented Oct 4, 2019

Also using yarn-deduplicae can help in many cases
https://github.com/atlassian/yarn-deduplicate

@spark1031
Copy link
Author

Thank you so much for your help everyone!! Really appreciate the time everyone took to help explain what might be going on for me and also really appreciate the new update =) Thank you again!

@lock
Copy link

lock bot commented Dec 27, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 27, 2019
svicalifornia added a commit to appjudo/mobx-orm that referenced this issue May 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants