-
Notifications
You must be signed in to change notification settings - Fork 125
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
Setting non-existent path in state works without devtools, throws error with devtools #1412
Comments
Hey, the same is happening for me. I did a bit of digging, and it comes from checkForComputed which, in contrast to the state update logic that does default to an empty object at each path, does not. I am not fully aware of the intentions of checkForComputed, but I believe it is just as a safety measure when developing. I guess it could then either allow paths that do not exist or make sure that any sub-path that does exist is not a computed. @christianalfoni Any thoughts on this? It would be really nice to get this sorted, and it seems (from my limited experience of an hour or so with this codebase) that it should be relatively easy once the proper behavior is defined :-) |
…oes not exist in state When the devtools are open, checkForComputed will try to access the current data that will be overwritten. When this data does not exist, it throws an error trying to access something on undefined ISSUES CLOSED: cerebral#1412
When setting a non-existent path in the state (using a tag and store.set), if devtools is turned off the path in the state is created appropriately. When devtools is turned on, the browser throws an error about reading a property of undefined on line 93 of Store.js in cerebral. The Cerebral debugger shows the value in the state as if it had been set appropriately in the first place.
To reproduce, simply do this in any action with devtools enabled in your app
store.set(state`path.does.not.exist`, 'hello');
This will throw an error in the console that "does" does not exist. Now look in the debugger and you will see a top-level state key named
path
whose value is an object that contains a key nameddoes
, .... and so on ... just as you would have expected. However, the browser code threw the error and stopped. If you catch the error and follow up with a get(statepath.does.not.exist
), you get undefined even though the debugger shows it in the state.Then disable devtools and repeat, and you will see that it works as expected.
As a workaround, you can manually loop through and create all the elements of the path one at a time in your app and it will work, but this is messy.
The text was updated successfully, but these errors were encountered: