framer-motion 12.24.8 → 12.24.10

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-C6mMBZjn.js');
7
+ var featureBundle = require('./feature-bundle-OJqyiRBo.js');
8
8
  var motionDom = require('motion-dom');
9
9
  var motionUtils = require('motion-utils');
10
10
 
package/dist/cjs/m.js CHANGED
@@ -850,69 +850,51 @@ for (const key in featureProps) {
850
850
 
851
851
  const motionComponentSymbol = Symbol.for("motionComponentSymbol");
852
852
 
853
- function isRefObject(ref) {
854
- return (ref &&
855
- typeof ref === "object" &&
856
- Object.prototype.hasOwnProperty.call(ref, "current"));
857
- }
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
- }
872
853
  /**
873
854
  * Creates a ref function that, when called, hydrates the provided
874
855
  * external ref and VisualElement.
875
856
  */
876
857
  function useMotionRef(visualState, visualElement, externalRef) {
877
- // Store the cleanup function from external ref if it returns one
878
- const externalRefCleanupRef = react.useRef(null);
858
+ /**
859
+ * Store externalRef in a ref to avoid including it in the useCallback
860
+ * dependency array. Including externalRef in dependencies causes issues
861
+ * with libraries like Radix UI that create new callback refs on each render
862
+ * when using asChild - this would cause the callback to be recreated,
863
+ * triggering element remounts and breaking AnimatePresence exit animations.
864
+ */
865
+ const externalRefContainer = react.useRef(externalRef);
866
+ react.useInsertionEffect(() => {
867
+ externalRefContainer.current = externalRef;
868
+ });
869
+ // Store cleanup function returned by callback refs (React 19 feature)
870
+ const refCleanup = react.useRef(null);
879
871
  return react.useCallback((instance) => {
880
872
  if (instance) {
881
- visualState.onMount && visualState.onMount(instance);
873
+ visualState.onMount?.(instance);
882
874
  }
883
875
  if (visualElement) {
884
- if (instance) {
885
- visualElement.mount(instance);
886
- }
887
- else {
888
- visualElement.unmount();
889
- }
876
+ instance ? visualElement.mount(instance) : visualElement.unmount();
890
877
  }
891
- if (externalRef) {
878
+ const ref = externalRefContainer.current;
879
+ if (typeof ref === "function") {
892
880
  if (instance) {
893
- // Mount: call the external ref and store any cleanup function
894
- const cleanup = setRef(externalRef, instance);
881
+ const cleanup = ref(instance);
895
882
  if (typeof cleanup === "function") {
896
- externalRefCleanupRef.current = cleanup;
883
+ refCleanup.current = cleanup;
897
884
  }
898
885
  }
886
+ else if (refCleanup.current) {
887
+ refCleanup.current();
888
+ refCleanup.current = null;
889
+ }
899
890
  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
- }
891
+ ref(instance);
909
892
  }
910
893
  }
911
- },
912
- /**
913
- * Include all dependencies to ensure the callback updates correctly
914
- */
915
- [visualElement, visualState, externalRef]);
894
+ else if (ref) {
895
+ ref.current = instance;
896
+ }
897
+ }, [visualElement]);
916
898
  }
917
899
 
918
900
  /**
@@ -928,6 +910,12 @@ const optimizedAppearDataAttribute = "data-" + camelToDash(optimizedAppearDataId
928
910
  */
929
911
  const SwitchLayoutGroupContext = react.createContext({});
930
912
 
913
+ function isRefObject(ref) {
914
+ return (ref &&
915
+ typeof ref === "object" &&
916
+ Object.prototype.hasOwnProperty.call(ref, "current"));
917
+ }
918
+
931
919
  const useIsomorphicLayoutEffect = isBrowser ? react.useLayoutEffect : react.useEffect;
932
920
 
933
921
  function useVisualElement(Component, visualState, props, createVisualElement, ProjectionNodeConstructor, isSVG) {