framer-motion 12.24.2 → 12.24.4

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.
@@ -4731,7 +4731,13 @@
4731
4731
  value.attach((v, set) => {
4732
4732
  latestValue = v;
4733
4733
  latestSetter = (latest) => set(parseValue(latest, unit));
4734
- frame.postRender(startAnimation);
4734
+ frame.postRender(() => {
4735
+ startAnimation();
4736
+ value['events'].animationStart?.notify();
4737
+ activeAnimation?.then(() => {
4738
+ value['events'].animationComplete?.notify();
4739
+ });
4740
+ });
4735
4741
  }, stopAnimation);
4736
4742
  if (isMotionValue(source)) {
4737
4743
  const removeSourceOnChange = source.on("change", (v) => value.set(parseValue(v, unit)));
@@ -5102,7 +5108,7 @@
5102
5108
  * Set a given ref to a given value
5103
5109
  * This utility takes care of different types of refs: callback refs and RefObject(s)
5104
5110
  */
5105
- function setRef(ref, value) {
5111
+ function setRef$1(ref, value) {
5106
5112
  if (typeof ref === "function") {
5107
5113
  return ref(value);
5108
5114
  }
@@ -5118,7 +5124,7 @@
5118
5124
  return (node) => {
5119
5125
  let hasCleanup = false;
5120
5126
  const cleanups = refs.map((ref) => {
5121
- const cleanup = setRef(ref, node);
5127
+ const cleanup = setRef$1(ref, node);
5122
5128
  if (!hasCleanup && typeof cleanup === "function") {
5123
5129
  hasCleanup = true;
5124
5130
  }
@@ -5136,7 +5142,7 @@
5136
5142
  cleanup();
5137
5143
  }
5138
5144
  else {
5139
- setRef(refs[i], null);
5145
+ setRef$1(refs[i], null);
5140
5146
  }
5141
5147
  }
5142
5148
  };
@@ -9696,11 +9702,26 @@
9696
9702
  Object.prototype.hasOwnProperty.call(ref, "current"));
9697
9703
  }
9698
9704
 
9705
+ /**
9706
+ * Set a given ref to a given value
9707
+ * This utility takes care of different types of refs: callback refs and RefObject(s)
9708
+ * Returns a cleanup function if the ref callback returns one (React 19 feature)
9709
+ */
9710
+ function setRef(ref, value) {
9711
+ if (typeof ref === "function") {
9712
+ return ref(value);
9713
+ }
9714
+ else if (isRefObject(ref)) {
9715
+ ref.current = value;
9716
+ }
9717
+ }
9699
9718
  /**
9700
9719
  * Creates a ref function that, when called, hydrates the provided
9701
9720
  * external ref and VisualElement.
9702
9721
  */
9703
9722
  function useMotionRef(visualState, visualElement, externalRef) {
9723
+ // Store the cleanup function from external ref if it returns one
9724
+ const externalRefCleanupRef = React$1.useRef(null);
9704
9725
  return React$1.useCallback((instance) => {
9705
9726
  if (instance) {
9706
9727
  visualState.onMount && visualState.onMount(instance);
@@ -9714,19 +9735,30 @@
9714
9735
  }
9715
9736
  }
9716
9737
  if (externalRef) {
9717
- if (typeof externalRef === "function") {
9718
- externalRef(instance);
9738
+ if (instance) {
9739
+ // Mount: call the external ref and store any cleanup function
9740
+ const cleanup = setRef(externalRef, instance);
9741
+ if (typeof cleanup === "function") {
9742
+ externalRefCleanupRef.current = cleanup;
9743
+ }
9719
9744
  }
9720
- else if (isRefObject(externalRef)) {
9721
- externalRef.current = instance;
9745
+ else {
9746
+ // Unmount: call stored cleanup function if available, otherwise call ref with null
9747
+ if (externalRefCleanupRef.current) {
9748
+ externalRefCleanupRef.current();
9749
+ externalRefCleanupRef.current = null;
9750
+ }
9751
+ else {
9752
+ // Fallback to React <19 behavior for refs that don't return cleanup
9753
+ setRef(externalRef, instance);
9754
+ }
9722
9755
  }
9723
9756
  }
9724
9757
  },
9725
9758
  /**
9726
- * Include externalRef in dependencies to ensure the callback updates
9727
- * when the ref changes, allowing proper ref forwarding.
9759
+ * Include all dependencies to ensure the callback updates correctly
9728
9760
  */
9729
- [visualElement]);
9761
+ [visualElement, visualState, externalRef]);
9730
9762
  }
9731
9763
 
9732
9764
  /**