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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var featureBundle = require('./feature-bundle-DBjkFz2c.js');
5
+ var featureBundle = require('./feature-bundle-BwaqZAbT.js');
6
6
  require('react');
7
7
  require('motion-dom');
8
8
  require('motion-utils');
@@ -4103,11 +4103,26 @@ function isRefObject(ref) {
4103
4103
  Object.prototype.hasOwnProperty.call(ref, "current"));
4104
4104
  }
4105
4105
 
4106
+ /**
4107
+ * Set a given ref to a given value
4108
+ * This utility takes care of different types of refs: callback refs and RefObject(s)
4109
+ * Returns a cleanup function if the ref callback returns one (React 19 feature)
4110
+ */
4111
+ function setRef(ref, value) {
4112
+ if (typeof ref === "function") {
4113
+ return ref(value);
4114
+ }
4115
+ else if (isRefObject(ref)) {
4116
+ ref.current = value;
4117
+ }
4118
+ }
4106
4119
  /**
4107
4120
  * Creates a ref function that, when called, hydrates the provided
4108
4121
  * external ref and VisualElement.
4109
4122
  */
4110
4123
  function useMotionRef(visualState, visualElement, externalRef) {
4124
+ // Store the cleanup function from external ref if it returns one
4125
+ const externalRefCleanupRef = React.useRef(null);
4111
4126
  return React.useCallback((instance) => {
4112
4127
  if (instance) {
4113
4128
  visualState.onMount && visualState.onMount(instance);
@@ -4121,19 +4136,30 @@ function useMotionRef(visualState, visualElement, externalRef) {
4121
4136
  }
4122
4137
  }
4123
4138
  if (externalRef) {
4124
- if (typeof externalRef === "function") {
4125
- externalRef(instance);
4139
+ if (instance) {
4140
+ // Mount: call the external ref and store any cleanup function
4141
+ const cleanup = setRef(externalRef, instance);
4142
+ if (typeof cleanup === "function") {
4143
+ externalRefCleanupRef.current = cleanup;
4144
+ }
4126
4145
  }
4127
- else if (isRefObject(externalRef)) {
4128
- externalRef.current = instance;
4146
+ else {
4147
+ // Unmount: call stored cleanup function if available, otherwise call ref with null
4148
+ if (externalRefCleanupRef.current) {
4149
+ externalRefCleanupRef.current();
4150
+ externalRefCleanupRef.current = null;
4151
+ }
4152
+ else {
4153
+ // Fallback to React <19 behavior for refs that don't return cleanup
4154
+ setRef(externalRef, instance);
4155
+ }
4129
4156
  }
4130
4157
  }
4131
4158
  },
4132
4159
  /**
4133
- * Include externalRef in dependencies to ensure the callback updates
4134
- * when the ref changes, allowing proper ref forwarding.
4160
+ * Include all dependencies to ensure the callback updates correctly
4135
4161
  */
4136
- [visualElement]);
4162
+ [visualElement, visualState, externalRef]);
4137
4163
  }
4138
4164
 
4139
4165
  /**
@@ -6325,4 +6351,4 @@ exports.useIsPresent = useIsPresent;
6325
6351
  exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
6326
6352
  exports.usePresence = usePresence;
6327
6353
  exports.visualElementStore = visualElementStore;
6328
- //# sourceMappingURL=feature-bundle-DBjkFz2c.js.map
6354
+ //# sourceMappingURL=feature-bundle-BwaqZAbT.js.map