Mobx: Breaking change in 5.15.5?

Created on 6 Aug 2020  ·  16Comments  ·  Source: mobxjs/mobx

Intended outcome:

Upgrade from 5.15.4 to 5.15.5, app still runs.

Actual outcome:

App runs with 5.15.4, but crashes on startup with 5.15.5. Seems many things that were previously working are now undefined.

Maybe side effect of https://github.com/mobxjs/mobx/issues/2386?

How to reproduce the issue:

If necessary I can try to put this together later. But given the extent of the breakage I assume it's not just me at the moment.

Versions

"mobx": "5.15.5",
"mobx-react-lite": "^2.0.7",
"mobx-state-tree": "^3.17.2",
"typescript": "^3.9.7"
🐛 bug

Most helpful comment

Fix has been released as 5.15.6 / 4.15.6. Thanks @urugator!

All 16 comments

@austinbutler Please give an example code. So I can try to find out the cause.

The https://github.com/mobxjs/mobx/issues/2386 has two modifications about extendObservable.

  1. doesn't include properties of object's prototype.
  2. include non-enumerable properties of object.

@austinbutler, please do provide a reproduction. Without this issue is inactionable.

Sorry about that, seems this issue it wasn't as broadly applicable as I'd assumed (which is good!).

I've put together a quick approximation of how it happens in my app. If you toggle between 5.15.4 and 5.15.5 in package.json you can see on .4 it loads fine, on .5 it crashes.

https://codesandbox.io/s/empty-dawn-76v4f

@urugator would you mind taking a look at this one? From the console logs in https://codesandbox.io/s/hidden-snowflake-2clmz?file=/src/Models.ts, at first sight it looks like the dehancer is not applied with for the .map of observable array, (it seems to be applied to the filter), so I guess the result from filter is not dehanced in #2348?

So this probably affects mobx-state-tree users only, as that is afaik the only thing using dehancers.

@mweststrate filter returns new non-observable array, so the map isn't called on observable array ... or?
EDIT: Ah sry, I've read it wrong, you're saying the filter is problematic
EDIT2: Yea, that makes sense ... the impl is wrong

Eh yeah I guess 🙂. Anyway it seems that map receives a still boxed value
in that example somehow.

Op do 6 aug. 2020 22:28 schreef urugator notifications@github.com:

@mweststrate https://github.com/mweststrate filter returns new
non-observable array, so the map isn't called on observable array ... or?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/mobxjs/mobx/issues/2423#issuecomment-670201036, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AAN4NBFJVY2YD4FQQBFFT3TR7MN7BANCNFSM4PWB6ZAA
.

How do I create array with enhancer/dehancer?

Nevermind I suppose ... based on MST sources, this seems to be the way:

const array = observable([{ value: 1 }, { value: 2 }, { value: 3 }]);
mobx._getAdministration(array).dehancer = ({ value }) => value;

Will PR tomorrow

I assume this is the same issue, for us array.find() breaks in MST.

Like after const result = self.items.find((item) => item.id === dataItem.id);
we can no longer call result.someAction().
Worked fine in older versions.

We have same issue with array.filter

Yes, all of these should be fixed in the PR #2426

Until it's released, either downgrade to 5.15.4 / 4.15.4 or a workaround:

array.slice().find // .filter/.whatever

EDIT: Changed map(x => x) to slice(). Didn't realize slice isn't affected. Thanks @k-g-a

Fix has been released as 5.15.6 / 4.15.6. Thanks @urugator!

Was this page helpful?
0 / 5 - 0 ratings