LearnNewsExamplesServices
Frontmatter
id8620
titleImplement Element.moveBefore() support for Atomic Moves
stateClosed
labels
aicore
assigneestobiu
createdAtJan 13, 2026, 11:08 PM
updatedAtJan 13, 2026, 11:35 PM
githubUrlhttps://github.com/neomjs/neo/issues/8620
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtJan 13, 2026, 11:35 PM

Implement Element.moveBefore() support for Atomic Moves

tobiu
tobiu commented on Jan 13, 2026, 11:08 PM

The current atomic move implementation in Neo.main.DeltaUpdates.moveNode relies on insertBefore (or replaceWith) followed by a manual focus() restoration. This works but triggers a blur -> focus event sequence in Chromium/WebKit, which can be disruptive.

The new Element.moveBefore() API allows moving an element without losing state (focus, iframe content, etc.) natively.

Requirements:

  1. In DeltaUpdates.moveNode, detect if parentNode.moveBefore is available.
  2. If available, use parentNode.moveBefore(node, siblingRef) instead of insertBefore.
  3. Skip the manual focus() restoration logic if moveBefore is used, as it preserves focus natively.
  4. Retain the current fallback logic for browsers that do not support moveBefore (e.g., Safari).

References:

tobiu
tobiu Jan 13, 2026, 11:35 PM

Input from Gemini 3 Pro:

✦ I have implemented the requested changes:

  1. Added nativeMoveBefore class field to Neo.main.DeltaUpdates for caching feature detection results.
  2. Updated moveNode to check for moveBefore support on the first run.
  3. If supported, moveNode now uses parentNode.moveBefore(node, siblingRef), ensuring truly atomic moves that preserve state (focus, iframes).
  4. If not supported (e.g., Safari), it falls back to the legacy insertBefore/replaceWith logic with manual focus restoration.

Verified via npm test (249 tests passed). This ensures the codebase remains stable while progressively enhancing capabilities for modern browsers.

coderabbitai cross-referenced by PR #740 on Aug 17, 2026, 7:40 AM