mithril.js: shouldNotUpdate throws an uncaught exception: vnode._state is undefined
When shouldNotUpdate attempts to query typeof vnode._state.onbeforeupdate, vnode._state evaluates to undefined and throws.
It’s unclear when vnode._state is set to this value - querying _state on the vnode in lifecycle methods always reveals an object.
I’ve tried to find the instances where _state is assigned to in Mithril source but in putting breakpoints at the moment state is assigned to _state, I can’t find an instance where state is undefined before the exception occurs.
Steps to Reproduce (for bugs)
https://barneycarroll.github.io/mle/
- Use the
+button in theNodeelement twice. - Observe the error:
Uncaught TypeError: Cannot read property 'onbeforeupdate' of undefined(Chrome) orTypeError: vnode._state is undefine(Firefox)
Your Environment
- Version used: 1.1.6
- Browser Name and version: Firefox 57.0.2 (64-bit), Chrome 63.0.3239.132 (Official Build) (64-bit)
- Operating System and version (desktop or mobile): Windows 10 Pro version 1709 build 16299.125
- Link to your project: https://github.com/barneycarroll/mle
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 24 (23 by maintainers)
Commits related to this issue
- Fix #2067 — committed to dead-claudia/mithril.js by dead-claudia 5 years ago
- Fix #2067 (#2447) * Fix #2067 * Add PR number [skip ci] — committed to MithrilJS/mithril.js by dead-claudia 5 years ago
got it.
When
shouldNotUpdateis true, we should also copy the rest of the state of the oldvnode(children,instance,dom) on the new one. Otherwise on the next cycle, the old vnode is unbaked, and thus unfit for diff.I believe I had this issue when I had a stream.map inside oninit. That stream.map had an m.redraw call which was what caused the issue. Isaiah then got me to do promise.resolve.then(m.redraw). Don’t know if it’s relevant but thought I’d add it here