#3849·motion

sortNodePosition throws when a sibling in enteringChildren has not mounted yet (Firefox: compareDocumentPosition: Argument 1 is not an object)

Author: karmahackerCreated Sep 25, 2026Updated Sep 25, 2026

Summary

VisualElement.sortNodePosition guards this.current but not other.current. When a child that mounts after its parent computes its stagger delay, calcChildStagger sorts parent.enteringChildren by DOM position; siblings that are registered but not mounted yet have current === null, and a.compareDocumentPosition(null) throws:

TypeError: Node.compareDocumentPosition: Argument 1 is not an object.   (Firefox)

Every child whose animateChanges throws never runs its initial → animate transition and stays at its initial values. In a Nuxt app the throw happens in a mounted hook during hydration and turns into the app's error page.

Why it only shows in Firefox

It depends on the argument order of Array.prototype.sort's comparator. SpiderMonkey's merge sort calls compare(earlier, later), so the already-mounted element is this and the unmounted sibling is other — the unguarded side. V8's insertion sort calls compare(pivot, existing) with the later (still unmounted) element as this, which hits the existing !this.current guard and returns 0. Same data, same code, different comparator order — which is why motiondivision/motion-vue#208 could not be reproduced in Chrome.

Where the unmounted siblings come from

motion-vue registers a child with its parent when the VisualElement is created, before it has mounted (motion-state.ts#L228), and animation-state.ts then calls calcChildStagger(parent.enteringChildren, …) for children mounting after the parent (animation-state.ts#L402-L405). The sort in motion-dom should not depend on every entry having an element, though — the guard for this.current already acknowledges that.

Code: packages/motion-dom/src/render/VisualElement.ts#L609-L621

Reproduction

Standalone page (motion-v 2.4.4 / motion-dom 13.4.4, Vue 3.5.43), full analysis and results in https://github.com/motiondivision/motion-vue/issues/208#issuecomment-5831915170. Open it in Firefox: 3 errors and 4 of 5 cards stuck at opacity: 0; Chromium: no errors.

At the unit level: two HTMLVisualElements, mount only one, mounted.sortNodePosition(unmounted) throws instead of returning 0.

Fix

Add !other.current || to the guard in sortNodePosition. PR follows.