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/

  1. Use the + button in the Node element twice.
  2. Observe the error: Uncaught TypeError: Cannot read property 'onbeforeupdate' of undefined (Chrome) or TypeError: 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

Most upvoted comments

got it.

When shouldNotUpdate is true, we should also copy the rest of the state of the old vnode (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