motion-dom 12.31.2 → 12.31.3

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/dist/cjs/index.js CHANGED
@@ -3367,11 +3367,15 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
3367
3367
  }
3368
3368
  }
3369
3369
  if (transitionEnd) {
3370
- Promise.all(animations).then(() => {
3371
- frame.update(() => {
3372
- transitionEnd && setTarget(visualElement, transitionEnd);
3373
- });
3370
+ const applyTransitionEnd = () => frame.update(() => {
3371
+ transitionEnd && setTarget(visualElement, transitionEnd);
3374
3372
  });
3373
+ if (animations.length) {
3374
+ Promise.all(animations).then(applyTransitionEnd);
3375
+ }
3376
+ else {
3377
+ applyTransitionEnd();
3378
+ }
3375
3379
  }
3376
3380
  return animations;
3377
3381
  }
@@ -5475,6 +5479,11 @@ class VisualElement {
5475
5479
  * if any motion values need to be removed after props are updated.
5476
5480
  */
5477
5481
  this.prevMotionValues = {};
5482
+ /**
5483
+ * Track whether this element has been mounted before, to detect
5484
+ * remounts after Suspense unmount/remount cycles.
5485
+ */
5486
+ this.hasBeenMounted = false;
5478
5487
  /**
5479
5488
  * An object containing a SubscriptionManager for each active event.
5480
5489
  */
@@ -5538,6 +5547,17 @@ class VisualElement {
5538
5547
  }
5539
5548
  }
5540
5549
  mount(instance) {
5550
+ /**
5551
+ * If this element has been mounted before (e.g. after a Suspense
5552
+ * unmount/remount), reset motion values to their initial state
5553
+ * so animations replay correctly from initial → animate.
5554
+ */
5555
+ if (this.hasBeenMounted) {
5556
+ for (const key in this.initialValues) {
5557
+ this.values.get(key)?.jump(this.initialValues[key]);
5558
+ this.latestValues[key] = this.initialValues[key];
5559
+ }
5560
+ }
5541
5561
  this.current = instance;
5542
5562
  visualElementStore.set(instance, this);
5543
5563
  if (this.projection && !this.projection.instance) {
@@ -5573,6 +5593,7 @@ class VisualElement {
5573
5593
  this.shouldSkipAnimations = this.skipAnimationsConfig ?? false;
5574
5594
  this.parent?.addChild(this);
5575
5595
  this.update(this.props, this.presenceContext);
5596
+ this.hasBeenMounted = true;
5576
5597
  }
5577
5598
  unmount() {
5578
5599
  this.projection && this.projection.unmount();