inferno: Inferno 1.6.1: Wrong error message for setState & maybe a breaking change.
I updated inferno to 1.6.1 and I got this error:
Inferno Error: cannot update state via setState() in componentWillUpdate() or constructor.
I didn’t use setState on those but in componentWillMount. The message is not correct and confusing. Additionally I think this change broke the possibility of setting up the state for server side rendering:
https://github.com/infernojs/inferno/commit/39d5922eb7e5e2a9093e505c72170b572200f9cd
If _blockSetState = true; by default then I can’t setup the state before to render. In the client side no problems because I can use componentDidMount (btw componentDidMount only runs in the client side).
Unless I am completely confused. How/Where I can setup the state before to render for SSR? cc @trueadm @Havunen
Thanks a lot for your help guys. We are rebuilding the redbull.tv site using inferno and we can’t be happier. The bundles are smaller and the site feels way faster for mobile and desktop.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (16 by maintainers)
Commits related to this issue
- Fix setState being blocked in SSR Github #1007 — committed to infernojs/inferno by deleted user 7 years ago
Yeah it sounds like bug or something really strange is happening there, also all our tests pass 😕
@hguillermo
contextis passed in as the 2nd argument to your constructor. We should probably define it too beforehand though in the base component. Rather than revert that commit, I’d rather_blockSetStateget set to false after the constructor has been executed.