-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
TypeError: 'set' on proxy: trap returned falsish for property '__proto__' #15
Comments
The component which you used try to re-define the property of observable of mobx, use a non-mobx observable data or class Model {
@observable.ref
data = []
} |
Thx~ But if use |
do not modify the array with |
Thx very much! But I don't understand what do u mean |
What u decorated with handleChangeModel() {
this.model.val.b.test = [
{
time: "我被改变了!"
}
];
this.model.val = {...this.model.val}
} To achieve the immutable approach u could try immer to reduce the verbose boilerplate code. |
sorry sorry I'm wrong and update https://codesandbox.io/s/lj3l95m09 |
but |
yep, |
Hi, Does that problem sounds familiar? |
Ok, so I managed to reproduce the problem: https://codesandbox.io/s/p7zwrvjrz7. I'm really annoyed because it used to work until we had to update vuetify which in turns forced us to update vue to at least version EDIT: A simpler example that does not use vuetify: https://codesandbox.io/s/k90k8kwn2r
|
After investigating more this PR vuejs/vue#7828 broke
|
@kuitos: Could you re-open this issue until a solution is found? |
@Nemikolh Thanks for your great efforts, I will look into it this weekend:smiley: |
@kuitos Sounds awesome! I will let you know if I found other/better solutions. |
@kuitos @Nemikolh As far as I know this is still broken with any version of Vue > 2.5.17. I did some debugging and tracing over the weekend and added some more detail on the Vue issue referenced above. I kinda doubt that the Vue team will do anything about this because they want to hook into the Array prototype to make the array observable. I added what I found there.
This is in the code here: https://github.com/mobxjs/mobx/blob/daf6ac0ac8dd369fb6179ec6a7fbbb231f383f9f/src/types/observablearray.ts#L96-L109 that @Nemikolh pointed out. Adding that check makes our apps "work" in that exceptions aren't thrown and errors aren't logged - everything seems to work, but I don't know... Do either of you have any thoughts on this? Should we open an issue on Mobx and see if there are any thoughts there? I'm a bit surprised this isn't a bigger issue - I thought more people were using Mobx with Vue. Thanks! |
Any update on this? I basically can't use any store that has arrays inside. |
Same problem here. I'm building a POC to evaluate a possible migration of an old codebase to MobX/Vue but an issue like this being ignored for months... |
sorry for the delay.. could u pls provide a codesandbox reproduction for a better problem checking? @albertodvc |
Thanks for the quick reply and sorry if my comment sounded a little rude. I will try to write one next week. |
OK, after some debugging I discovered this. It filters data out for Vue, so if you pass MobX observable in Vue component's In one of my Stores I had this to make TS correctly resolve type of 'playlists', I found it there:
MobX'
but MobX denies replacing of proto:
To sum up: in my case it was because some of my classes in fact were not observable by MobX. I will try to dig more into MobX internals but for my case it was because I didn't use TLDR: if you get this error, it means that you in fact use MobX and mobx-vue bindings wrong and your app isn't working correctly under the hood. |
Speaking about this comment and reproduction link: this is wrong usage of mobx-vue. When you write this
you make store an When you do this:
Even toJS won't help you there because it will not convert s recursively since s isn't an observable, but s.arr is an observable and toJS stops when it sees first non-observable object. The correct way to use above example is this. It seems that you have to use ViewModel instance to make a bridge between Vue and MobX, at least I didn't find an another way. Obviously I'm not that familiar with internals of mobx and mobx-vue, maybe I assumed something wrong but it doesn't seem so judging by a code. |
Here is a sandbox with my case. It only fails on chrome. |
@albertodvc it fails in every browser, it's not related to Chrome. If you use ViewModel class example it will work correctly. |
Another solution without a class is to wrap your data in
I have not discovered better way to do it. I guess it's still possible though to make it better. |
@mxs42 It works fine in Safari. |
@albertodvc oh I don't have Safari because I'm on Windows. It's not related to item being 'observable', it's related to the way Vue works. When you write this
you tell Vue to observe item. Now when you assign something to |
Thanks for your time and explanation @mxs42. I think I could live with your wrapper solution, but there are a few things I still don't understand:
I'm starting to doubt MobX/Vue is a solid option to migrate my app. I have to go with Vue (corporate desition) It sounded nice we could rewrite our AngularJS state to mobx and start migrating component by component to Vue but now I'm afraid MobX integration with Vue could imply more and more hacks in the future. |
now
Sadly yes, I feel the same. I'm using MobX/Vue currently for new app but this situation made me think about possible alternatives. I can't stand Flux/Vuex because of all this boilerplate and triggering different actions by their names passed as strings. And I also don't like React, although it seems that MobX works better with React. |
@mxs42 @albertodvc Really appreciate the discussions here, and the similar observations. I enjoyed migrating an app to Vue until I added Vuex - similar complaints about typical flux/redux boilerplate, triggers, and string passing, and beyond that the complete inability to leverage Typescript was a deal-breaker. I got excited again when I started converting Vuex to Mobx because of the clarity of the classes/stores (and the inherent Typescript support) - until lots of little edge cases like this and others pretty much showed that Vue's reactivity system won't play nicely with others to the point that I'm now considering migrating to Ember Octane or Svelte.. |
@kevlarr consider moving all state to MobX, i.e. if you need to compute something from I currently continue to develop my app using MobX. Yes, it's not that amazing how I thought it is going to be but flux-like libraries is a big no-no for me. I wish Vue had better mechanism to use 3rd party state management though. Also: I found that Habitica uses own implementation of Vuex without mutations. Might be a source for inspiration to create your own state management. Svelte sounds great on paper but they got their own problems, the biggest one is that Svelte isn't that popular so you can't expect to see many 3rd party libraries and I personally find their syntax questionable. Vue would be perfect if we had an ability to integrate MobX better but yea, our web-development world is far from perfect lol |
I wrote comment above and realized again how fucked is a modern web development. We have to use thousands lines of code and another thousands lines to connect different lines of code to each other just to get things done. Many hacks and wrappers, complex build systems (and infinite amount of difficulties while trying to do something bigger than TodoMVC), total bullshit! Sorry for offtopic, just needed to speak out lol |
@mxs42 Yeah, agreed on Svelte - I re-read some of their docs and lost some interest, and same with Octane (I used to use Ember but disliked a lot of its patterns, and not enough is being 'fixed').. I'll check out how Habitica does state management with Vue, that sounds interesting! @kuitos mentioned moving all state to Mobx and I had not really thought of that as a good pattern before, but both of you make it sound pretty compelling now.
Way too true haha. Off-topic or not, I enjoyed it! Makes me feel a lot more sane, too. Web front-end development is such a mire. |
Ahhh, I was so hoping Mobx-vue to be my replacement for vuex-module-decorators. But I've also hit this error. I'm really frustrated with TypeScript and Vue at the moment. Even considering a full rewrite to Angular even though I hate its enterprisy boilerplate and fast paced dev cycle. |
Personally I finished small internal project without using any 3rd party state management library.
I didn't use TypeScript for this so it was bad in terms of autocompletion and IDE suggestions but I guess you can use typings for this. |
@mxs42 Nice, I think that's pretty similar to an email blast that Michael Thiessen sent out a week ago called "Why I don't use Vuex".. He was presenting an alternative of just using a Vue component as a store and injecting it where necessary (or just passing down via props) |
Hi @mxs42, I just wanted to thank you for coming up with a solution. I agree that the solution is not great. In my opinion the problem is that |
Pls help, why is not working
This is demo
https://codesandbox.io/s/lj3l95m09
Thx!
The text was updated successfully, but these errors were encountered: