framer-motion 12.24.9 → 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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var featureBundle = require('./feature-bundle-Cw8jj9v7.js');
5
+ var featureBundle = require('./feature-bundle-OJqyiRBo.js');
6
6
  require('react');
7
7
  require('motion-dom');
8
8
  require('motion-utils');
@@ -4105,69 +4105,51 @@ const useSVGVisualState = /*@__PURE__*/ makeUseVisualState({
4105
4105
 
4106
4106
  const motionComponentSymbol = Symbol.for("motionComponentSymbol");
4107
4107
 
4108
- function isRefObject(ref) {
4109
- return (ref &&
4110
- typeof ref === "object" &&
4111
- Object.prototype.hasOwnProperty.call(ref, "current"));
4112
- }
4113
-
4114
- /**
4115
- * Set a given ref to a given value
4116
- * This utility takes care of different types of refs: callback refs and RefObject(s)
4117
- * Returns a cleanup function if the ref callback returns one (React 19 feature)
4118
- */
4119
- function setRef(ref, value) {
4120
- if (typeof ref === "function") {
4121
- return ref(value);
4122
- }
4123
- else if (isRefObject(ref)) {
4124
- ref.current = value;
4125
- }
4126
- }
4127
4108
  /**
4128
4109
  * Creates a ref function that, when called, hydrates the provided
4129
4110
  * external ref and VisualElement.
4130
4111
  */
4131
4112
  function useMotionRef(visualState, visualElement, externalRef) {
4132
- // Store the cleanup function from external ref if it returns one
4133
- const externalRefCleanupRef = React.useRef(null);
4113
+ /**
4114
+ * Store externalRef in a ref to avoid including it in the useCallback
4115
+ * dependency array. Including externalRef in dependencies causes issues
4116
+ * with libraries like Radix UI that create new callback refs on each render
4117
+ * when using asChild - this would cause the callback to be recreated,
4118
+ * triggering element remounts and breaking AnimatePresence exit animations.
4119
+ */
4120
+ const externalRefContainer = React.useRef(externalRef);
4121
+ React.useInsertionEffect(() => {
4122
+ externalRefContainer.current = externalRef;
4123
+ });
4124
+ // Store cleanup function returned by callback refs (React 19 feature)
4125
+ const refCleanup = React.useRef(null);
4134
4126
  return React.useCallback((instance) => {
4135
4127
  if (instance) {
4136
- visualState.onMount && visualState.onMount(instance);
4128
+ visualState.onMount?.(instance);
4137
4129
  }
4138
4130
  if (visualElement) {
4139
- if (instance) {
4140
- visualElement.mount(instance);
4141
- }
4142
- else {
4143
- visualElement.unmount();
4144
- }
4131
+ instance ? visualElement.mount(instance) : visualElement.unmount();
4145
4132
  }
4146
- if (externalRef) {
4133
+ const ref = externalRefContainer.current;
4134
+ if (typeof ref === "function") {
4147
4135
  if (instance) {
4148
- // Mount: call the external ref and store any cleanup function
4149
- const cleanup = setRef(externalRef, instance);
4136
+ const cleanup = ref(instance);
4150
4137
  if (typeof cleanup === "function") {
4151
- externalRefCleanupRef.current = cleanup;
4138
+ refCleanup.current = cleanup;
4152
4139
  }
4153
4140
  }
4141
+ else if (refCleanup.current) {
4142
+ refCleanup.current();
4143
+ refCleanup.current = null;
4144
+ }
4154
4145
  else {
4155
- // Unmount: call stored cleanup function if available, otherwise call ref with null
4156
- if (externalRefCleanupRef.current) {
4157
- externalRefCleanupRef.current();
4158
- externalRefCleanupRef.current = null;
4159
- }
4160
- else {
4161
- // Fallback to React <19 behavior for refs that don't return cleanup
4162
- setRef(externalRef, instance);
4163
- }
4146
+ ref(instance);
4164
4147
  }
4165
4148
  }
4166
- },
4167
- /**
4168
- * Include all dependencies to ensure the callback updates correctly
4169
- */
4170
- [visualElement, visualState, externalRef]);
4149
+ else if (ref) {
4150
+ ref.current = instance;
4151
+ }
4152
+ }, [visualElement]);
4171
4153
  }
4172
4154
 
4173
4155
  /**
@@ -4175,6 +4157,12 @@ function useMotionRef(visualState, visualElement, externalRef) {
4175
4157
  */
4176
4158
  const SwitchLayoutGroupContext = React.createContext({});
4177
4159
 
4160
+ function isRefObject(ref) {
4161
+ return (ref &&
4162
+ typeof ref === "object" &&
4163
+ Object.prototype.hasOwnProperty.call(ref, "current"));
4164
+ }
4165
+
4178
4166
  function useVisualElement(Component, visualState, props, createVisualElement, ProjectionNodeConstructor, isSVG) {
4179
4167
  const { visualElement: parent } = React.useContext(MotionContext);
4180
4168
  const lazyContext = React.useContext(LazyContext);
@@ -6372,4 +6360,4 @@ exports.useIsPresent = useIsPresent;
6372
6360
  exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
6373
6361
  exports.usePresence = usePresence;
6374
6362
  exports.visualElementStore = visualElementStore;
6375
- //# sourceMappingURL=feature-bundle-Cw8jj9v7.js.map
6363
+ //# sourceMappingURL=feature-bundle-OJqyiRBo.js.map