Hi I see the following exception. However, it does not give me enough StackTrace, so I cannot find out where goes wrong :( Is this a bug of the mobx.dart framework? (I saw this port but the post said the bug is fixed)
P.S. I have made config.disableErrorBoundaries = true when setting up.
Thanks very much!
鈺愨晲鈺愨晲鈺愨晲鈺愨晲 Exception caught by flutter_mobx 鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲鈺愨晲
The following MobXCaughtException was thrown:
setState() or markNeedsBuild() called when widget tree was locked.
This Observer widget cannot be marked as needing to build because the framework is locked.
The widget on which setState() or markNeedsBuild() was called was:
Observer
When the exception was thrown, this was the stack:
#0 Element.markNeedsBuild.<anonymous closure> (package:flutter/src/widgets/framework.dart:4172:9)
#1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4182:6)
#2 ObserverElementMixin.invalidate (package:flutter_mobx/src/observer_widget_mixin.dart:70:24)
#3 ReactionImpl._run (package:mobx/src/core/reaction.dart:119:22)
#4 ReactiveContext._runReactionsInternal (package:mobx/src/core/context.dart:345:18)
I don't believe you can get more info out of these kind of errors are picked up by Flutter as part of its rendering process. These generally occur when there's a build method has code that is trying to modify the state of a widget as part of trying to render the associated widget. With MobX, this likely means you have code in build method that is triggering an action to mutate of an observable.
Thanks very much for the hint! I will try to figure out more about that!
P.S. I am confused why cannot we get more info? If some code trigger an action or modify a state, that code must be in the stack, IMHO.
As far as I know, this has to do with how the rendering process works. Refer to the docs for setState https://api.flutter.dev/flutter/widgets/State/setState.html where it mentions a build is scheduled. So it's like saying this widget is "dirty" can you rebuild it and it's descendents when you got cycles to do so. This is different from running regular sequential code where you can trace the code
Thanks for the explanation! Now I see it :)
@MaikuB
Actually IMHO at least one piece of information is very helpful: Which Observer causes this problem? Without this, I have no idea where to debug... Even it is not sequential code like you have kindly explained, there must be one Observer who triggers the problem. Currently, it just says "an Observer" but there are thousands of Observers in my code!
Thanks!
Have you tried putting names to your observers to see if that helps?
Edit: you may also want to try enabling spying https://mobx.netlify.app/api/spy to help track the issue
Also if a name doesn't work then try a key. From a quick test I tried, this works. Note that the exception you're seeing actually comes from Flutter not MobX. The exception is a MobXCaughtException to indicate that MobX caught the exception that got thrown. So I believe that unless Flutter itself can add more information, this isn't something MobX can address
Thanks very much! I will have a try about using keys as well as using spy!
Most helpful comment
As far as I know, this has to do with how the rendering process works. Refer to the docs for setState https://api.flutter.dev/flutter/widgets/State/setState.html where it mentions a
buildis scheduled. So it's like saying this widget is "dirty" can you rebuild it and it's descendents when you got cycles to do so. This is different from running regular sequential code where you can trace the code