solidjs-motion 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solidjs-motion",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "An animation library for SolidJS — port of motion/react patterns built on the framework-agnostic motion package",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/presence.tsx CHANGED
@@ -204,6 +204,19 @@ export const Presence: Component<PresenceProps> = (props) => {
204
204
  runEnters.set(el, runEnter)
205
205
  },
206
206
  beforeMount: (el) => {
207
+ // Fires the runEnter for THE tracked element that transition-group
208
+ // is signalling via onEnter / onChange.added. Nested motion
209
+ // descendants of this element do NOT have their runEnter fired
210
+ // here — they handle their own readiness via createMotion's
211
+ // isConnected-based fallback (see the comment at that fallback
212
+ // site for why). Doing the subtree walk here was tried and
213
+ // misfired during wait-mode nested-Presence swaps: NESTED
214
+ // Presence's onEnter runs synchronously while NESTED's Panel is
215
+ // still off-DOM inside the outer page-transition holding pen, so
216
+ // flipping enterReady=true would dispatch animate to a
217
+ // disconnected element and the WAAPI commitStyles would silently
218
+ // drop, leaving the element painted at its animate target with
219
+ // no visible transition.
207
220
  const fn = runEnters.get(el)
208
221
  runEnters.delete(el)
209
222
  fn?.()
@@ -482,20 +482,47 @@ export function createMotion(
482
482
  const inPresence = presence.registerEnter !== undefined
483
483
  const [enterReady, setEnterReady] = createSignal(!inPresence)
484
484
  if (inPresence && presence.registerEnter) {
485
- presence.registerEnter(el, () => setEnterReady(true))
486
- // Fallback: transition-group's onEnter / onChange.added only fires for
487
- // elements that are NEW to the source list. The initial children of a
488
- // `<Presence initial={false}>` (appear=false case) are already in the
489
- // signal at construction and never trigger an enter callback. We flip
490
- // readiness from a microtask if the element is connected by then —
491
- // Solid's synchronous render of `returned()` has run, and any element
492
- // that was meant to be on screen is in the DOM. For wait-mode swaps
493
- // where the new child is still off-DOM (the old one's exit is in
494
- // flight), the `isConnected` check fails and we leave readiness false;
495
- // Presence will fire beforeMount through onEnter when the exit settles.
496
- queueMicrotask(() => {
497
- if (el.isConnected) setEnterReady(true)
485
+ // Single source of truth for readiness: `el.isConnected`. The diff
486
+ // effect's first iteration must NOT fire animate against a
487
+ // disconnected element motion's WAAPI animation runs to completion
488
+ // off-DOM, then silently drops `commitStyles`, leaving the element
489
+ // painted at its `initial` target with no visible transition.
490
+ //
491
+ // Both signals that could trip readiness are routed through this
492
+ // function:
493
+ //
494
+ // 1. Presence's `beforeMount(el)` callback fires when
495
+ // transition-group inserts the tracked element. For a tracked
496
+ // direct child of Presence, by the time this fires the element
497
+ // is in the DOM, so `isConnected` is true and we flip
498
+ // immediately. For a NESTED motion element inside a deeper
499
+ // Presence whose `onEnter` fires synchronously during render
500
+ // (while the surrounding outer-Presence-tracked subtree is
501
+ // STILL off-DOM in a holding pen), `isConnected` is false and
502
+ // we schedule a retry.
503
+ //
504
+ // 2. The initial-microtask fallback — for cases where Presence's
505
+ // `beforeMount` doesn't fire at all (e.g., a `<Presence
506
+ // initial={false}>` appear=false case, where transition-group
507
+ // doesn't raise enter for the initial source items).
508
+ //
509
+ // The rAF retry self-terminates the moment `setEnterReady(true)`
510
+ // fires; the `live` flag (cleared via `onCleanup`) prevents leaks
511
+ // if the owner is disposed before insertion ever happens.
512
+ let live = true
513
+ onCleanup(() => {
514
+ live = false
498
515
  })
516
+ const checkConnection = (): void => {
517
+ if (!live) return
518
+ if (el.isConnected) {
519
+ setEnterReady(true)
520
+ return
521
+ }
522
+ requestAnimationFrame(checkConnection)
523
+ }
524
+ presence.registerEnter(el, checkConnection)
525
+ queueMicrotask(checkConnection)
499
526
  }
500
527
 
501
528
  // ---------- Gesture state machine (Q3b, ADR 0002) ----------