Skip to content
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

Open
aultac opened this issue Sep 26, 2019 · 1 comment · May be fixed by #1438
Open

Setting non-existent path in state works without devtools, throws error with devtools #1412

aultac opened this issue Sep 26, 2019 · 1 comment · May be fixed by #1438

Comments

@aultac
Copy link

aultac commented Sep 26, 2019

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 named does, .... 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.

@JohannesAnd
Copy link
Contributor

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 :-)

JohannesAnd added a commit to JohannesAnd/cerebral that referenced this issue Sep 17, 2021
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants