-
Notifications
You must be signed in to change notification settings - Fork 58
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
[optimization] child node reordering #8
Comments
It seems like adding an ID check could also be a cheap optimization. |
That's what keys do in react, some prior art. |
Is there a way we can do children node reordering without having to force the user to supply a identifying key for every element? Problem is when the children look alike but children's-children contains the changing content. Apart from creating a Merkle tree or having the user supply a key I cannot see any other way of doing it. I would love to help with this. ✨ |
@reminyborg well, each DOM element is just an object. If we set a property on the object we could use it as a unique identifier for the child nodes; removing the need for stuff to happen in userland. I think at least; hmmmm |
@yoshuawuyts i might be wrong, in the cases of reordering with only the children's-children changing we might still end up mutating the elements instead of moving them. The effects are probably most apparent when dealing with focus. A possible solution would be a optional "key" property. It would simplify reordering and keeping DOM state like focus intact. And if "key" is not used we can solve it optimistically. EDIT: I prefer morphdom's solution: Adding an ID id check on the elements as @kristoferjoseph suggested, requiring that works great for the edge cases where we want to keep a sub tree's DOM state intact (focus, input values, etc.) when reordering. Should also be suggested for optimising complex lists. Its not apparent from morphdoms docs. We should add this to the readme when the feature ready. |
+1 on ID check |
Hehe, I think for all intents and purposes cache-element / nanocomponent
achieves what I initially proposed for merkle trees ✨
…On Fri, Jan 20, 2017, 16:41 kj ***@***.***> wrote:
+1 on ID check
Also Merkel Trees is such and interesting idea we should def add an
experimental branch that tries this out.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACWleqiyrhs6Dc5Mu5ZybNlK8EU9OTJCks5rUNWsgaJpZM4JfAfi>
.
|
I was thinking about what to name this prop, and
Also from infernojs/inferno#406:
This made me realize that if we want to prevent |
blep, ok I think we might need to rename it to |
I was experimenting with the thought that using the element ID would be enough. I was reading morphdoms reasonings about it in patrick-steele-idem/morphdom#3 It would require users to create document unique ID's when needing list performance or preserving DOM state. But it would also ensure that the 'children' could survive being moved to another place in the tree. |
@reminyborg ah this explains a lot - I've run into issues before where I set an id on an element and it would stop updating. Didn't know why, just considered it a morphdom gotcha. I'm not necessarily a fan of using IDs as keys, because IDs meant to be unique per page which means there could be conflicts. Using a |
actually IDs might make sense - if we document it well tho ✨ - less new words to invent |
I've found in working on an infinite list module (https://github.com/editdata/infinite-elements) that having an id or key for reordering is essential for making it work. Using the id by default and providing the option of using an alternate key attribute might be good. morphdom has a |
Yeah fair point about the config, though I'd like to try a no-config
version first - the more consistent user land becomes the better it is I
think. I think using IDs for reordering shouldn't give us a lot of trouble
…On Sun, Mar 12, 2017, 22:05 Seth Vincent ***@***.***> wrote:
I've found in working on an infinite list module (
https://github.com/editdata/infinite-elements) that having an id or key
for reordering is essential for making it work.
Using the id by default and providing the option of using an alternate key
attribute might be good. morphdom has a getNodeKey option to accomplish
this.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACWlejkxouWA32KzCC4CXGeFkvQDHSW-ks5rlF4MgaJpZM4JfAfi>
.
|
From IRC: 17:04 <yoshuawuyts> how about: look over list of elements, reference each child by an id in an object, reference new children by id in object, morph nodes with same id, then loop over nodes and skip the ones that have already been morphed (e.g. do the reordering part)
17:05 <julian> yeah that sounds good, but doesn't solve the on-load problem, right?
17:06 <yoshuawuyts> it would because we never remove them from the dom
17:06 <julian> how do you reorder AB to BA without removing a node?
17:06 <yoshuawuyts> oh fuck lol
17:07 <julian> maybe on-load needs to be changed to allow this
17:07 <julian> yes i think so
17:07 <julian> it should after deletion check if "the same element" doesn't exist after all, maybe like that?
17:08 <yoshuawuyts> dang, reordering lists is tricky. appending / prepending nodes is the easier case
17:08 <julian> yeah definitely
17:09 <julian> deleting and adding in between works too
17:09 <julian> just reordering
17:09 <yoshuawuyts> luckily onload is a different concern - if we solve the algo in nanomorph then we can figure out how to best do stuff with onload on top of that
17:09 <julian> ok, cool!
17:09 <yoshuawuyts> I think at least haha
17:09 <julian> it "has to be that way"
17:09 <julian> not much we can do in nanomorph otherwise
17:10 <yoshuawuyts> yeahh
17:10 <julian> on-load should work with the concept of moving elements around
17:10 <julian> that should be a basic premise
17:10 <yoshuawuyts> we could so something like: listen for onload events -> nextTick -> check if currently in DOM -> if not in DOM fire the onunload handler
17:11 <yoshuawuyts> which would allow for detaching -> immediately reattaching DOM nodes
17:11 <julian> yeah i was thinking the same
17:11 <yoshuawuyts> woot! |
Patch to fix this was merged, but current master shows a regression in certain cases: This was from my CSSconf talk slides, when upgrading to new nanomorph things failed. Oooops. https://github.com/yoshuawuyts/css-conf-talk/tree/master |
Wondering how this could affect reordered components that return a proxy. |
The idea is that it'd do away with artifacts accidentally being rendered (:
…On Thu, May 18, 2017 at 10:45 PM Bret Comnes ***@***.***> wrote:
Wondering how this could affect reordered components that return a proxy.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACWlejgJt8E3MIuTdyVzm3fIWqNF-9YRks5r7K36gaJpZM4JfAfi>
.
|
Fantastic. I suspected so. |
choojs/nanohtml#74 fixed the regression I encountered - haven't been able to reproduce. We should stay on the lookout for possible regressions tho |
|
This is going to be shipped in |
So @developit pointed out another optimization we could do is check node reordering. Often times lists get updated; items get appended or removed. Given that lists, forms and links are the staple elements of HTML this is probably worth optimizing for.
The new node comparison algorithm would then become:
I reckon this should speed up the reordering case by quite a bunch. Help welcome! ✨
The text was updated successfully, but these errors were encountered: