Current vnode `dom` property is undefined in `onbeforeupdate`
martinboulais opened this issue · comments
Mithril.js version: 2.2.2
Browser and OS: Firefox 118.0.2 (64-bit) on Ubuntu 22.04.3 LTS
Code
Steps to Reproduce
- Click on the button to increment the counter
Expected Behavior
I expect the value of vnode.dom
to be the actual dom in onbeforeupdate
, as it is in onupdate
. If this is not the expected behavior, maybe it should be explicited in the documentation.
Current Behavior
Currently vnode.dom
is undefined in onbeforeupdate
Hello :) I think vnode.dom
will always be undefined
in onbeforeupdate
. The reason why it shows the dom
after a while, is that you're using a reference to the vnode
, which by then has updated. If you deconstruct (or copy) the vnode, it'll stay undefined
: flems.
Hello,
Thank you for your quick reply. I used a reference on purpose, to be sure that the node that is provided is the one that will be used after the update, which makes sense.
The fact that it is named old
mislead me. If I am not wrong, old
actually contain the current
vnode, and the first argument is passed the future
vnode, which indeed do not have a dom element yet.
Closing the issue, thanks!
@martinboulais If it helps, the current, most recently received vnode, hasn't been rendered yet, only the previous, old one. The hook exists to know whether to render the current vnode.