Skip to content

Use moveBefore when available to preserve DOM state#2459

Open
mathieumahe wants to merge 1 commit intoSortableJS:masterfrom
mathieumahe:master
Open

Use moveBefore when available to preserve DOM state#2459
mathieumahe wants to merge 1 commit intoSortableJS:masterfrom
mathieumahe:master

Conversation

@mathieumahe
Copy link

Description

This PR updates the code to use the new moveBefore() method when it is available, and falls back to insertBefore() otherwise.

Unlike insertBefore(), moveBefore() allows moving a node without removing it from the DOM, which preserves its internal state and ongoing behavior.

This has several important benefits:

  • Component state is preserved
  • CSS animations are not reset
  • Embedded content such as iframes is not reloaded (e.g. TinyMCE editors, YouTube videos, etc.)

References

MDN: Element.moveBefore()
https://developer.mozilla.org/en-US/docs/Web/API/Element/moveBefore#movebefore_constraints

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

Labels

None yet

1 participant