-
Notifications
You must be signed in to change notification settings - Fork 127
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
Loosing DOM state when prepending element #200
Comments
FWIW, I originally stumbled across this as my element scroll position was getting lost. The input focus is just a smaller use-case easier to test against
This is extremely misleading as the morphdom algorithm comes with this same cost. I couldn't find a version without this behavior. It appears to build down to the use of appendChild |
You'll find a lot of the diffing algorithms have the same problem with prepending to the tree. Curious though if this is on the roadmap to fix? |
@tropperstyle I'd have to take a deep look at this. As you mentioned, once we detect a change, we throw a grenade at the siblings and children. However, if they exist in cache by id, we stitch them back together. This seems to still lose the I'm not sure of a good solution yet. Seems like we would have to keep a cache of focused state around and add that that back to the DOM after we have traversed the tree. Surely something that would be nice for this library to handle. Just not sure of a good solution... |
So, tracking focus explicitly wouldn't have helped in my case as I discovered this issue after loosing |
Hey @snewcomer, I've been trying to find a solution to this problem for several days. It cuts deeper than just focus and scroll state. We're finding that if you insert a new sibling, two additional problems emerge when you "grenade" siblings.
I'm willing to PR this but I feel like I'm a bit under water trying to figure out how to attack this. I've been trying to figure out a way to get siblings enumerated in Is this on your horizon, Scott? Do you have any idea how to best go about implementing this functionality? |
Environment
Expected behavior
Calling morphdom to prepend a element to the container should keep the previous active input element focus
Actual behavior
The browser state and input focus is lost
Reproduce
I tried adding an ID to every element, even the newly introduced element.
https://jsfiddle.net/kajr2zmv/
All console.log statements expected to be
true
The text was updated successfully, but these errors were encountered: