Skip to content

[Live] Improving child render handling: avoid removing element from DOM when possible #1561

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

Merged

Conversation

weaverryan
Copy link
Member

@weaverryan weaverryan commented Mar 1, 2024

Q A
Bug fix? yes
New feature? no
Issues Fixes the timer on https://ux.symfony.com/demos/live-memory/ (which currently resets each time you select the first card)
License MIT

Hi!

TODO

  • Test case for child morphing when position is kept (prove that the element is never removed from the DOM)
  • Test case for child morphing when child moves, but another element takes its place (prove that the final HTML is the expected).

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!

@carsonbot carsonbot added the Status: Needs Review Needs to be reviewed label Mar 1, 2024
@weaverryan weaverryan mentioned this pull request Mar 1, 2024
@kbond kbond merged commit 85dab79 into symfony:2.x Mar 1, 2024
@weaverryan weaverryan force-pushed the live-improve-child-preserve-rendering branch from 6bf2ac6 to 603d653 Compare March 1, 2024 15:33
@weaverryan weaverryan deleted the live-improve-child-preserve-rendering branch March 1, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants