-
-
Notifications
You must be signed in to change notification settings - Fork 924
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
shouldNotUpdate throws an uncaught exception: vnode._state is undefined #2067
Comments
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 |
The app does play tricks with the redraw loop (part of the app is meant to draw in response to the draw loop of the other 😬) so something along those lines isn't beyond the realms of possibility. But — aren't the failure cases for lifecycle / redraw triggers either noop or infinite loop? I don't understand how things could get any more complicated than that from a Mithril internals perspective. |
@barneycarroll Are you mutating a |
@pygy I'm relying on a state property of I renamed the reference to avoid confusion, the problem persists… |
@barneycarroll By any chance, does this repro with Also, you block every @pygy From digging through the debugger, it's erroring on this node specifically, just not finding the component's Found a lead, though, for v1 at least: @barneycarroll Talk about obscure bugs...this is a torture cell... 😟 😄 |
As for so far, I feel like I've not even scratched the surface at this point. |
|
I'm re-opening this to see if it repros against v2 with |
@barneycarroll If you update your utility to |
@isiahmeadows hi! |
@barneycarroll Could you come up with an automated repro that doesn't require individual clicks? Something that only requires |
When |
@pygy That might do it. I for some dumb reason thought we kept the previous subtree, or I would've caught it and fixed it years ago. 😄 Can't wait until I can review your eventual PR for this. 🙂 👍 |
Actually, we already copy |
Another option would be to drop support for Edit: at least, stop the "skip diff" part. Not sure where that hook would otherwise be useful though... |
@pygy we could loose |
@barneycarroll Good point. That approach means that we keep "skip diff if |
@pygy If we drop Alternatively, we could just have people return But in either case, I'd rather not encourage people to memoize vnode instances on their own. Mithril's allowed to as it owns them and controls them, but users are not since they give their vnodes to Mithril - they don't just lend them like they do in React and similar. (Unlike JS or even TS, Rust provides types to verify this, but because this is in JS, we have to rely on conventions for it.) |
But in either case, this really needs fixed in v1 and v2. |
What other type enforcement other than "readonly instance" on the vnode given to view we need? |
@charlag None, really. I was just referencing why we discourage vnode memoization compared to why React allows (and encourages it) in terms of Rust's lifetimes and borrowing. |
Note to self for later: find time to get the fix implemented and landed in the main branch. Not an explicit v2 blocker, but it's something I want to get in ASAP. |
Reduced the issue to three variants, one missed in the initial investigation: 1 2 3 When you go to view it, open the browser console. Flems just unhelpfully shows "Script error". The first one results in an error like that of this bug. The second results in a DOM node going mysteriously missing. The third prints a wrong attribute value. All three have a nearly identical root cause. Stepping through each variant, it's not as simple as @pygy's initial suggested fix made it seem, but his follow-up is almost there. What's happening is that somehow the old vnodes that Mithril has are getting crossed up with data that's never used. So what I'm getting is this:
It may have seemed like Fix finally incoming! |
When
shouldNotUpdate
attempts to querytypeof vnode._state.onbeforeupdate
,vnode._state
evaluates toundefined
and throws.It's unclear when
vnode._state
is set to this value - querying_state
on thevnode
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 momentstate
is assigned to_state
, I can't find an instance wherestate
isundefined
before the exception occurs.Steps to Reproduce (for bugs)
https://barneycarroll.github.io/mle/
+
button in theNode
element twice.Uncaught TypeError: Cannot read property 'onbeforeupdate' of undefined
(Chrome) orTypeError: vnode._state is undefine
(Firefox)Your Environment
The text was updated successfully, but these errors were encountered: