framer-motion 12.24.3 → 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.
package/dist/cjs/index.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var React = require('react');
7
- var featureBundle = require('./feature-bundle-DBjkFz2c.js');
7
+ var featureBundle = require('./feature-bundle-BwaqZAbT.js');
8
8
  var motionDom = require('motion-dom');
9
9
  var motionUtils = require('motion-utils');
10
10
 
package/dist/cjs/m.js CHANGED
@@ -856,11 +856,26 @@ function isRefObject(ref) {
856
856
  Object.prototype.hasOwnProperty.call(ref, "current"));
857
857
  }
858
858
 
859
+ /**
860
+ * Set a given ref to a given value
861
+ * This utility takes care of different types of refs: callback refs and RefObject(s)
862
+ * Returns a cleanup function if the ref callback returns one (React 19 feature)
863
+ */
864
+ function setRef(ref, value) {
865
+ if (typeof ref === "function") {
866
+ return ref(value);
867
+ }
868
+ else if (isRefObject(ref)) {
869
+ ref.current = value;
870
+ }
871
+ }
859
872
  /**
860
873
  * Creates a ref function that, when called, hydrates the provided
861
874
  * external ref and VisualElement.
862
875
  */
863
876
  function useMotionRef(visualState, visualElement, externalRef) {
877
+ // Store the cleanup function from external ref if it returns one
878
+ const externalRefCleanupRef = react.useRef(null);
864
879
  return react.useCallback((instance) => {
865
880
  if (instance) {
866
881
  visualState.onMount && visualState.onMount(instance);
@@ -874,19 +889,30 @@ function useMotionRef(visualState, visualElement, externalRef) {
874
889
  }
875
890
  }
876
891
  if (externalRef) {
877
- if (typeof externalRef === "function") {
878
- externalRef(instance);
892
+ if (instance) {
893
+ // Mount: call the external ref and store any cleanup function
894
+ const cleanup = setRef(externalRef, instance);
895
+ if (typeof cleanup === "function") {
896
+ externalRefCleanupRef.current = cleanup;
897
+ }
879
898
  }
880
- else if (isRefObject(externalRef)) {
881
- externalRef.current = instance;
899
+ else {
900
+ // Unmount: call stored cleanup function if available, otherwise call ref with null
901
+ if (externalRefCleanupRef.current) {
902
+ externalRefCleanupRef.current();
903
+ externalRefCleanupRef.current = null;
904
+ }
905
+ else {
906
+ // Fallback to React <19 behavior for refs that don't return cleanup
907
+ setRef(externalRef, instance);
908
+ }
882
909
  }
883
910
  }
884
911
  },
885
912
  /**
886
- * Include externalRef in dependencies to ensure the callback updates
887
- * when the ref changes, allowing proper ref forwarding.
913
+ * Include all dependencies to ensure the callback updates correctly
888
914
  */
889
- [visualElement]);
915
+ [visualElement, visualState, externalRef]);
890
916
  }
891
917
 
892
918
  /**