This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Suggestion: allow Hyperscript selectors to be used in the diffing algorithm #1976
Labels
Area: Core
For anything dealing with Mithril core itself
Area: Documentation
For anything dealing mainly with the documentation itself
Type: Breaking Change
For any feature request or suggestion that could reasonably break existing code
Type: Enhancement
For any feature request or suggestion that isn't a bug fix
Currently, people are getting confused by
cond ? m(".foo") : m(".bar")
not diffing as expected. It's come up quite a few times in Gitter by now, and it leads to some pretty subtle user bugs.Expected Behavior
What many people are expecting is that
m(".foo")
andm(".bar")
are treated as different elements, and I'm suggesting using that as part of the node's identity, as if it were part of the node's tag name.Current Behavior
Currently, Mithril sees
m(".foo")
as no more thanm("div", {className: "foo"})
, and diffs based on the tag name itself.Possible Solution
Add a check here to also check for the Hyperscript selector along with the tag name heuristic.
Context
It'd avoid subtle bugs like in this, where
oncreate
doesn't fire like you'd visually expect ifvnode.state.loading
is initiallytrue
.Edit: An alternative to this would be to document the behavior as a common gotcha, recommending the use of
key
as applicable.The text was updated successfully, but these errors were encountered: