LearnNewsExamplesServices
Frontmatter
id8620
titleImplement Element.moveBefore() support for Atomic Moves
stateClosed
labels
aicorefeature
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
blockedBy[]
blocking[]
closedAtJan 13, 2026, 11:35 PM

Implement Element.moveBefore() support for Atomic Moves

Closed v11.21.0 aicorefeature
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 added the ai label on Jan 13, 2026, 11:08 PM
tobiu added the core label on Jan 13, 2026, 11:08 PM
tobiu added the feature label on Jan 13, 2026, 11:08 PM
tobiu assigned to @tobiu on Jan 13, 2026, 11:10 PM
tobiu referenced in commit e37a640 - "feat: Implement Element.moveBefore support for atomic moves (#8620)" on Jan 13, 2026, 11:35 PM
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.

tobiu closed this issue on Jan 13, 2026, 11:35 PM