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

getInitialState() returning something weird followed by setState() has the world's worst error message #397

Closed
petehunt opened this issue Oct 2, 2013 · 4 comments

Comments

@petehunt
Copy link
Contributor

petehunt commented Oct 2, 2013

See http://jsfiddle.net/nbJVN/

Return a string from getInitialState() and call setState(). You get this amazing error message:

Uncaught Error: Critical assumptions about the merge functions have been violated. This is the fault of the merge functions themselves, not necessarily the callers. 
@zpao
Copy link
Member

zpao commented Oct 2, 2013

We should probably add an invariant that whatever is returned from getInitialState is in fact an object.

@vjeux
Copy link
Contributor

vjeux commented Oct 2, 2013

Invariant all the things :)

@dkvasnicka
Copy link

This also seems to apply when using an array, not the string only. Which makes it a pretty real-world bug IMHO (compared to the weird string scenario).
Or is there a reason you don't want states to be arrays?

@zpao
Copy link
Member

zpao commented Dec 12, 2013

This will happen whenever state is anything but an Object (I think there is a check in there for arrays). Since we use merge it needs to be an object, arrays are no good either.

@benjamn benjamn closed this as completed in 77697f2 Jan 2, 2014
benjamn added a commit that referenced this issue Jan 2, 2014
Add invariant to check getInitialState return value. Fixes #397.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants