[Live] Improving child render handling: avoid removing element from DOM when possible #1561
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
TODO
Long explanation 😛
When handling child rendering - and
data-live-preserve
- the goal is to "preserve" the element on the page instead of morphing it from the matching id in the new HTML. This is especially challenging if the "id" element has changed position, requiring an algorithm where we store the "original" elements, clone them (to avoid morphing from mutating the originals) then swap them back in at the correct position after.However, instead of doing this "replace and swap" in all situations, we now only do it when the matching elements change position. If they do not (if a
data-live-preserve
element's original element and new element are in the same position - which would happen 99% of the time), then avoid the "replace and swap" and simply tell Idiomorph to avoid morphing the element. This handles and edge case where the original element has a CSS transition. Removing it and re-adding it to the DOM - even for a moment - resets/restarts that CSS transition unnecessarily.Cheers!