Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Fix #3648:
observableRequiresReaction
/computedRequiresReaction
shouldn't warn withenableStaticRendering(true)
#3649base: main
Are you sure you want to change the base?
Fix #3648:
observableRequiresReaction
/computedRequiresReaction
shouldn't warn withenableStaticRendering(true)
#3649Changes from all commits
fbbc2db
e9c3aee
b05595b
aac2142
47beb21
76806b2
17c6f2d
d33d2c7
452832f
5688e72
2a6190b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is wrong on multiple levels:
I don't recall changing state in render should ever throw, with a slight exception of
autoAction
, which doesn't work ATM as mentioned elsewhere.It doesn't
expect(...).toThrow()
, it just checks for the error (that is never thrown).If it's about
enforceAction
, it should expectconsole.warn
instead of an error.It pollutes console with
Warning: Cannot update a component while rendering a different component
(this is a bit surprising given that only one component is involved, but not a concern atm).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a breaking change? By default we allow state reads outside reactive contexts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. These flags,
allowStateReads
andallowStateChanges
, says whether you're in a context, where reads/changes are allowed - or perhaps better - where they are supposed to take place. They're basicallyinDerivation
/inAction
flags - they're switched on/off when entering/leaving these, regardless of whether it should warn or not. We use these flags instead of directly checking foraction
/derivation
, because the mapping isn't always exactly 1:1. But really the point is to demark these places, not to directly control the warning - the warning is always only raised in combination withrequiresReaction
/enforceAction
. They should always start asfalse
, because there is no running action/derivation by default.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check, that adds up. I haven't been working on this for too long 😅.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out it's more complicated. I think it was originally designed as described, but it was maybe misunderstood and changed with the introduction of
autoAction
.The thing is that
autoAction
is supposed to warn when you modify state inside derivation, regardless ofenforceAction
configuration. SoautoAction
assumes that ifallowStateChanges
is false, there will be a warning when setting state, no other conditions needed.In order for this to work the
configure/resetGlobalState
was updated to synchronizeallowStateChanges
withenforeAction
configuration.But the actual check for the warning doesn't assume this behavior:
mobx/packages/mobx/src/core/derivation.ts
Lines 140 to 143 in 13a222e
Notice there is a bug - the check doesn't respect
enforceActions: "never"
(enforceActions === false).This bug is actually a reason why the test for
autoAction
warning is passing - there is a test above that callsmobx.configure({ enforceActions: "never" })
.If you fix this bug, the
autoAction
warning (Side effects like changing state are not allowed) can never occur.