Skip to content

Conversation

@barneycarroll
Copy link
Member

By ensuring component instances are always lists - even if the view output is a single node - key can be used for identification semantics universally. This also makes vnode traversal easier, since it standardizes component instance type.

There component tests for self-returning vnodes are failing for reasons I don't understand.

render/render.js Outdated
initComponent(vnode, hooks)
if (vnode.instance != null) {
if (vnode.instance === vnode) throw Error("A view cannot return the vnode it received as arguments")
if (vnode.instance[0] === vnode) throw Error("A view cannot return the vnode it received as arguments")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't passing the associated tests. Any insights appreciated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's odd... it should work... Looking into it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vnode.normalize() turns the array into a fragment, it should be vnode.instance.children[0].

Note that this is the kind of change that will most likely affect perf negatively (adding one updateNodes() per component to the call stack), even if we define vnode.instance = Vnode.normalize(output).children and change downstream methods to deal with it.

@barneycarroll barneycarroll changed the title Attempt at fixing #1713 Component instances are always fragments - fixes #1713 Mar 16, 2017
@dead-claudia
Copy link
Member

@barneycarroll LGTM, mod (lack of) tests. Given the documented grief it caused in #1713, tests would be preferred here.

@dead-claudia dead-claudia added the Status: Needs test case For pull requests that lack one or more test cases for the feature or behavior in question label Mar 17, 2017
@pygy
Copy link
Member

pygy commented Mar 17, 2017

Actually, this is only a partial fix, in that it adds another special case for the component instance, but doesn't fix keys out of lists further down the tree...

Adding a check for vnode.key===old.key in updateNode would probably be universal.

@barneycarroll
Copy link
Member Author

Intriguing insight @pygy. Can it really be that simple?

@isiahmeadows 👍

@pygy pygy mentioned this pull request Mar 17, 2017
@pygy
Copy link
Member

pygy commented Mar 17, 2017

@barneycarroll I think so, but I'll need to look in depth. #1724 describes in depth what I meant by " keys out of lists further down the tree" in my previous comment.

@barneycarroll
Copy link
Member Author

@pygy that's a really nasty test case. Try restructuring that code to meet author-land requirements (eg fragments, changed keys on single element) and it reveals further difficulties…

@pygy
Copy link
Member

pygy commented Mar 17, 2017

@barneycarroll I had read the #1724 code too fast, it was a case of mixed keyed/non-keyed nodes.

barneycarroll added a commit to barneycarroll/mithril.js that referenced this pull request Mar 18, 2017
Attempt to fix MithrilJS#1713, superseding MithrilJS#1720, as per @pygy's insight here MithrilJS#1720 (comment)
@barneycarroll
Copy link
Member Author

Closing this in favour of #1725

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Needs test case For pull requests that lack one or more test cases for the feature or behavior in question

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants