framer-motion 6.2.4 → 6.2.5

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
@@ -4349,6 +4349,12 @@ var gestureAnimations = {
4349
4349
  hover: makeRenderlessComponent(useHoverGesture),
4350
4350
  };
4351
4351
 
4352
+ var counter = 0;
4353
+ var incrementId = function () { return counter++; };
4354
+ var useId = React__namespace.useId
4355
+ ? React__namespace.useId
4356
+ : function () { return useConstant(incrementId); };
4357
+
4352
4358
  /**
4353
4359
  * When a component is the child of `AnimatePresence`, it can use `usePresence`
4354
4360
  * to access information about whether it's still present in the React tree.
@@ -4379,8 +4385,8 @@ function usePresence() {
4379
4385
  var isPresent = context.isPresent, onExitComplete = context.onExitComplete, register = context.register;
4380
4386
  // It's safe to call the following hooks conditionally (after an early return) because the context will always
4381
4387
  // either be null or non-null for the lifespan of the component.
4382
- // Replace with useOpaqueId when released in React
4383
- var id = useUniqueId();
4388
+ // Replace with useId when released in React
4389
+ var id = useId();
4384
4390
  React.useEffect(function () { return register(id); }, []);
4385
4391
  var safeToRemove = function () { return onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(id); };
4386
4392
  return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
@@ -4411,9 +4417,6 @@ function useIsPresent() {
4411
4417
  function isPresent(context) {
4412
4418
  return context === null ? true : context.isPresent;
4413
4419
  }
4414
- var counter = 0;
4415
- var incrementId = function () { return counter++; };
4416
- var useUniqueId = function () { return useConstant(incrementId); };
4417
4420
 
4418
4421
  function shallowCompare(next, prev) {
4419
4422
  if (!Array.isArray(prev))
@@ -6118,6 +6121,7 @@ var visualElement = function (_a) {
6118
6121
  if (isVariantNode && parent && !isControllingVariants) {
6119
6122
  removeFromVariantTree = parent === null || parent === void 0 ? void 0 : parent.addVariantChild(element);
6120
6123
  }
6124
+ values.forEach(function (value, key) { return bindToMotionValue(key, value); });
6121
6125
  parent === null || parent === void 0 ? void 0 : parent.children.add(element);
6122
6126
  element.setProps(props);
6123
6127
  },
@@ -7098,12 +7102,22 @@ function createDomMotionComponent(key) {
7098
7102
  */
7099
7103
  var m = createMotionProxy(createDomMotionConfig);
7100
7104
 
7105
+ function useIsMounted() {
7106
+ var isMounted = React.useRef(false);
7107
+ React.useLayoutEffect(function () {
7108
+ isMounted.current = true;
7109
+ return function () {
7110
+ isMounted.current = false;
7111
+ };
7112
+ }, []);
7113
+ return isMounted;
7114
+ }
7115
+
7101
7116
  function useForceUpdate() {
7102
- var isUnmountingRef = React.useRef(false);
7117
+ var isMounted = useIsMounted();
7103
7118
  var _a = tslib.__read(React.useState(0), 2), forcedRenderCount = _a[0], setForcedRenderCount = _a[1];
7104
- useUnmountEffect(function () { return (isUnmountingRef.current = true); });
7105
7119
  var forceRender = React.useCallback(function () {
7106
- !isUnmountingRef.current && setForcedRenderCount(forcedRenderCount + 1);
7120
+ isMounted.current && setForcedRenderCount(forcedRenderCount + 1);
7107
7121
  }, [forcedRenderCount]);
7108
7122
  /**
7109
7123
  * Defer this to the end of the next animation frame in case there are multiple
@@ -7113,16 +7127,10 @@ function useForceUpdate() {
7113
7127
  return [deferredForceRender, forcedRenderCount];
7114
7128
  }
7115
7129
 
7116
- var presenceId = 0;
7117
- function getPresenceId() {
7118
- var id = presenceId;
7119
- presenceId++;
7120
- return id;
7121
- }
7122
7130
  var PresenceChild = function (_a) {
7123
7131
  var children = _a.children, initial = _a.initial, isPresent = _a.isPresent, onExitComplete = _a.onExitComplete, custom = _a.custom, presenceAffectsLayout = _a.presenceAffectsLayout;
7124
7132
  var presenceChildren = useConstant(newChildrenMap);
7125
- var id = useConstant(getPresenceId);
7133
+ var id = useId();
7126
7134
  var context = React.useMemo(function () { return ({
7127
7135
  id: id,
7128
7136
  initial: initial,
@@ -7174,17 +7182,14 @@ function newChildrenMap() {
7174
7182
  return new Map();
7175
7183
  }
7176
7184
 
7177
- function getChildKey(child) {
7178
- return child.key || "";
7179
- }
7185
+ var getChildKey = function (child) { return child.key || ""; };
7186
+ var isDev = process.env.NODE_ENV !== "production";
7180
7187
  function updateChildLookup(children, allChildren) {
7181
- var seenChildren = process.env.NODE_ENV !== "production" ? new Set() : null;
7188
+ var seenChildren = isDev ? new Set() : null;
7182
7189
  children.forEach(function (child) {
7183
7190
  var key = getChildKey(child);
7184
- if (process.env.NODE_ENV !== "production" && seenChildren) {
7185
- if (seenChildren.has(key)) {
7186
- console.warn("Children of AnimatePresence require unique keys. \"".concat(key, "\" is a duplicate."));
7187
- }
7191
+ if (isDev && seenChildren && seenChildren.has(key)) {
7192
+ console.warn("Children of AnimatePresence require unique keys. \"".concat(key, "\" is a duplicate."));
7188
7193
  seenChildren.add(key);
7189
7194
  }
7190
7195
  allChildren.set(key, child);
@@ -7240,29 +7245,34 @@ var AnimatePresence = function (_a) {
7240
7245
  var forceRenderLayoutGroup = React.useContext(LayoutGroupContext).forceRender;
7241
7246
  if (forceRenderLayoutGroup)
7242
7247
  forceRender = forceRenderLayoutGroup;
7243
- var isInitialRender = React.useRef(true);
7244
- var isMounted = React.useRef(true);
7245
- React.useEffect(function () { return function () {
7246
- isMounted.current = false;
7247
- }; }, []);
7248
+ var isMounted = useIsMounted();
7248
7249
  // Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key
7249
7250
  var filteredChildren = onlyElements(children);
7251
+ var childrenToRender = filteredChildren;
7252
+ var exiting = new Set();
7250
7253
  // Keep a living record of the children we're actually rendering so we
7251
7254
  // can diff to figure out which are entering and exiting
7252
- var presentChildren = React.useRef(filteredChildren);
7255
+ var presentChildren = React.useRef(childrenToRender);
7253
7256
  // A lookup table to quickly reference components by key
7254
7257
  var allChildren = React.useRef(new Map()).current;
7255
- // A living record of all currently exiting components.
7256
- var exiting = React.useRef(new Set()).current;
7257
- updateChildLookup(filteredChildren, allChildren);
7258
7258
  // If this is the initial component render, just deal with logic surrounding whether
7259
7259
  // we play onMount animations or not.
7260
- if (isInitialRender.current) {
7260
+ var isInitialRender = React.useRef(true);
7261
+ useIsomorphicLayoutEffect(function () {
7261
7262
  isInitialRender.current = false;
7262
- return (React__namespace.createElement(React__namespace.Fragment, null, filteredChildren.map(function (child) { return (React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, initial: initial ? undefined : false, presenceAffectsLayout: presenceAffectsLayout }, child)); })));
7263
+ updateChildLookup(filteredChildren, allChildren);
7264
+ presentChildren.current = childrenToRender;
7265
+ });
7266
+ useUnmountEffect(function () {
7267
+ isInitialRender.current = true;
7268
+ allChildren.clear();
7269
+ exiting.clear();
7270
+ });
7271
+ if (isInitialRender.current) {
7272
+ return (React__namespace.createElement(React__namespace.Fragment, null, childrenToRender.map(function (child) { return (React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, initial: initial ? undefined : false, presenceAffectsLayout: presenceAffectsLayout }, child)); })));
7263
7273
  }
7264
7274
  // If this is a subsequent render, deal with entering and exiting children
7265
- var childrenToRender = tslib.__spreadArray([], tslib.__read(filteredChildren), false);
7275
+ childrenToRender = tslib.__spreadArray([], tslib.__read(childrenToRender), false);
7266
7276
  // Diff the keys of the currently-present and target children to update our
7267
7277
  // exiting list.
7268
7278
  var presentKeys = presentChildren.current.map(getChildKey);
@@ -7274,10 +7284,6 @@ var AnimatePresence = function (_a) {
7274
7284
  if (targetKeys.indexOf(key) === -1) {
7275
7285
  exiting.add(key);
7276
7286
  }
7277
- else {
7278
- // In case this key has re-entered, remove from the exiting list
7279
- exiting.delete(key);
7280
- }
7281
7287
  }
7282
7288
  // If we currently have exiting children, and we're deferring rendering incoming children
7283
7289
  // until after all current children have exiting, empty the childrenToRender array
@@ -7303,9 +7309,8 @@ var AnimatePresence = function (_a) {
7303
7309
  // Defer re-rendering until all exiting children have indeed left
7304
7310
  if (!exiting.size) {
7305
7311
  presentChildren.current = filteredChildren;
7306
- if (isMounted.current === false) {
7312
+ if (isMounted.current === false)
7307
7313
  return;
7308
- }
7309
7314
  forceRender();
7310
7315
  onExitComplete && onExitComplete();
7311
7316
  }
@@ -7318,7 +7323,6 @@ var AnimatePresence = function (_a) {
7318
7323
  var key = child.key;
7319
7324
  return exiting.has(key) ? (child) : (React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, presenceAffectsLayout: presenceAffectsLayout }, child));
7320
7325
  });
7321
- presentChildren.current = childrenToRender;
7322
7326
  if (process.env.NODE_ENV !== "production" &&
7323
7327
  exitBeforeEnter &&
7324
7328
  childrenToRender.length > 1) {
@@ -8289,13 +8293,15 @@ function useAnimatedState(initialState) {
8289
8293
  });
8290
8294
  React.useEffect(function () {
8291
8295
  element.mount({});
8292
- return element.unmount();
8293
- }, []);
8296
+ return element.unmount;
8297
+ }, [element]);
8294
8298
  React.useEffect(function () {
8295
8299
  element.setProps({
8296
- onUpdate: function (v) { return setAnimationState(tslib.__assign({}, v)); },
8300
+ onUpdate: function (v) {
8301
+ setAnimationState(tslib.__assign({}, v));
8302
+ },
8297
8303
  });
8298
- });
8304
+ }, [setAnimationState, element]);
8299
8305
  var startAnimation = useConstant(function () { return function (animationDefinition) {
8300
8306
  return animateVisualElement(element, animationDefinition);
8301
8307
  }; });
@@ -43,13 +43,15 @@ function useAnimatedState(initialState) {
43
43
  });
44
44
  useEffect(function () {
45
45
  element.mount({});
46
- return element.unmount();
47
- }, []);
46
+ return element.unmount;
47
+ }, [element]);
48
48
  useEffect(function () {
49
49
  element.setProps({
50
- onUpdate: function (v) { return setAnimationState(__assign({}, v)); },
50
+ onUpdate: function (v) {
51
+ setAnimationState(__assign({}, v));
52
+ },
51
53
  });
52
- });
54
+ }, [setAnimationState, element]);
53
55
  var startAnimation = useConstant(function () { return function (animationDefinition) {
54
56
  return animateVisualElement(element, animationDefinition);
55
57
  }; });
@@ -3,17 +3,12 @@ import * as React from 'react';
3
3
  import { useMemo } from 'react';
4
4
  import { PresenceContext } from '../../context/PresenceContext.mjs';
5
5
  import { useConstant } from '../../utils/use-constant.mjs';
6
+ import { useId } from '../../utils/use-id.mjs';
6
7
 
7
- var presenceId = 0;
8
- function getPresenceId() {
9
- var id = presenceId;
10
- presenceId++;
11
- return id;
12
- }
13
8
  var PresenceChild = function (_a) {
14
9
  var children = _a.children, initial = _a.initial, isPresent = _a.isPresent, onExitComplete = _a.onExitComplete, custom = _a.custom, presenceAffectsLayout = _a.presenceAffectsLayout;
15
10
  var presenceChildren = useConstant(newChildrenMap);
16
- var id = useConstant(getPresenceId);
11
+ var id = useId();
17
12
  var context = useMemo(function () { return ({
18
13
  id: id,
19
14
  initial: initial,
@@ -1,21 +1,21 @@
1
1
  import { __read, __spreadArray } from 'tslib';
2
2
  import * as React from 'react';
3
- import { useContext, useRef, useEffect, cloneElement, Children, isValidElement } from 'react';
3
+ import { useContext, useRef, cloneElement, Children, isValidElement } from 'react';
4
4
  import { useForceUpdate } from '../../utils/use-force-update.mjs';
5
+ import { useIsMounted } from '../../utils/use-is-mounted.mjs';
5
6
  import { PresenceChild } from './PresenceChild.mjs';
6
7
  import { LayoutGroupContext } from '../../context/LayoutGroupContext.mjs';
8
+ import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs';
9
+ import { useUnmountEffect } from '../../utils/use-unmount-effect.mjs';
7
10
 
8
- function getChildKey(child) {
9
- return child.key || "";
10
- }
11
+ var getChildKey = function (child) { return child.key || ""; };
12
+ var isDev = process.env.NODE_ENV !== "production";
11
13
  function updateChildLookup(children, allChildren) {
12
- var seenChildren = process.env.NODE_ENV !== "production" ? new Set() : null;
14
+ var seenChildren = isDev ? new Set() : null;
13
15
  children.forEach(function (child) {
14
16
  var key = getChildKey(child);
15
- if (process.env.NODE_ENV !== "production" && seenChildren) {
16
- if (seenChildren.has(key)) {
17
- console.warn("Children of AnimatePresence require unique keys. \"".concat(key, "\" is a duplicate."));
18
- }
17
+ if (isDev && seenChildren && seenChildren.has(key)) {
18
+ console.warn("Children of AnimatePresence require unique keys. \"".concat(key, "\" is a duplicate."));
19
19
  seenChildren.add(key);
20
20
  }
21
21
  allChildren.set(key, child);
@@ -71,29 +71,34 @@ var AnimatePresence = function (_a) {
71
71
  var forceRenderLayoutGroup = useContext(LayoutGroupContext).forceRender;
72
72
  if (forceRenderLayoutGroup)
73
73
  forceRender = forceRenderLayoutGroup;
74
- var isInitialRender = useRef(true);
75
- var isMounted = useRef(true);
76
- useEffect(function () { return function () {
77
- isMounted.current = false;
78
- }; }, []);
74
+ var isMounted = useIsMounted();
79
75
  // Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key
80
76
  var filteredChildren = onlyElements(children);
77
+ var childrenToRender = filteredChildren;
78
+ var exiting = new Set();
81
79
  // Keep a living record of the children we're actually rendering so we
82
80
  // can diff to figure out which are entering and exiting
83
- var presentChildren = useRef(filteredChildren);
81
+ var presentChildren = useRef(childrenToRender);
84
82
  // A lookup table to quickly reference components by key
85
83
  var allChildren = useRef(new Map()).current;
86
- // A living record of all currently exiting components.
87
- var exiting = useRef(new Set()).current;
88
- updateChildLookup(filteredChildren, allChildren);
89
84
  // If this is the initial component render, just deal with logic surrounding whether
90
85
  // we play onMount animations or not.
91
- if (isInitialRender.current) {
86
+ var isInitialRender = useRef(true);
87
+ useIsomorphicLayoutEffect(function () {
92
88
  isInitialRender.current = false;
93
- return (React.createElement(React.Fragment, null, filteredChildren.map(function (child) { return (React.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, initial: initial ? undefined : false, presenceAffectsLayout: presenceAffectsLayout }, child)); })));
89
+ updateChildLookup(filteredChildren, allChildren);
90
+ presentChildren.current = childrenToRender;
91
+ });
92
+ useUnmountEffect(function () {
93
+ isInitialRender.current = true;
94
+ allChildren.clear();
95
+ exiting.clear();
96
+ });
97
+ if (isInitialRender.current) {
98
+ return (React.createElement(React.Fragment, null, childrenToRender.map(function (child) { return (React.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, initial: initial ? undefined : false, presenceAffectsLayout: presenceAffectsLayout }, child)); })));
94
99
  }
95
100
  // If this is a subsequent render, deal with entering and exiting children
96
- var childrenToRender = __spreadArray([], __read(filteredChildren), false);
101
+ childrenToRender = __spreadArray([], __read(childrenToRender), false);
97
102
  // Diff the keys of the currently-present and target children to update our
98
103
  // exiting list.
99
104
  var presentKeys = presentChildren.current.map(getChildKey);
@@ -105,10 +110,6 @@ var AnimatePresence = function (_a) {
105
110
  if (targetKeys.indexOf(key) === -1) {
106
111
  exiting.add(key);
107
112
  }
108
- else {
109
- // In case this key has re-entered, remove from the exiting list
110
- exiting.delete(key);
111
- }
112
113
  }
113
114
  // If we currently have exiting children, and we're deferring rendering incoming children
114
115
  // until after all current children have exiting, empty the childrenToRender array
@@ -134,9 +135,8 @@ var AnimatePresence = function (_a) {
134
135
  // Defer re-rendering until all exiting children have indeed left
135
136
  if (!exiting.size) {
136
137
  presentChildren.current = filteredChildren;
137
- if (isMounted.current === false) {
138
+ if (isMounted.current === false)
138
139
  return;
139
- }
140
140
  forceRender();
141
141
  onExitComplete && onExitComplete();
142
142
  }
@@ -149,7 +149,6 @@ var AnimatePresence = function (_a) {
149
149
  var key = child.key;
150
150
  return exiting.has(key) ? (child) : (React.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, presenceAffectsLayout: presenceAffectsLayout }, child));
151
151
  });
152
- presentChildren.current = childrenToRender;
153
152
  if (process.env.NODE_ENV !== "production" &&
154
153
  exitBeforeEnter &&
155
154
  childrenToRender.length > 1) {
@@ -1,6 +1,6 @@
1
1
  import { useContext, useEffect } from 'react';
2
2
  import { PresenceContext } from '../../context/PresenceContext.mjs';
3
- import { useConstant } from '../../utils/use-constant.mjs';
3
+ import { useId } from '../../utils/use-id.mjs';
4
4
 
5
5
  /**
6
6
  * When a component is the child of `AnimatePresence`, it can use `usePresence`
@@ -32,8 +32,8 @@ function usePresence() {
32
32
  var isPresent = context.isPresent, onExitComplete = context.onExitComplete, register = context.register;
33
33
  // It's safe to call the following hooks conditionally (after an early return) because the context will always
34
34
  // either be null or non-null for the lifespan of the component.
35
- // Replace with useOpaqueId when released in React
36
- var id = useUniqueId();
35
+ // Replace with useId when released in React
36
+ var id = useId();
37
37
  useEffect(function () { return register(id); }, []);
38
38
  var safeToRemove = function () { return onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(id); };
39
39
  return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
@@ -64,8 +64,5 @@ function useIsPresent() {
64
64
  function isPresent(context) {
65
65
  return context === null ? true : context.isPresent;
66
66
  }
67
- var counter = 0;
68
- var incrementId = function () { return counter++; };
69
- var useUniqueId = function () { return useConstant(incrementId); };
70
67
 
71
68
  export { isPresent, useIsPresent, usePresence };
@@ -161,6 +161,7 @@ var visualElement = function (_a) {
161
161
  if (isVariantNode && parent && !isControllingVariants) {
162
162
  removeFromVariantTree = parent === null || parent === void 0 ? void 0 : parent.addVariantChild(element);
163
163
  }
164
+ values.forEach(function (value, key) { return bindToMotionValue(key, value); });
164
165
  parent === null || parent === void 0 ? void 0 : parent.children.add(element);
165
166
  element.setProps(props);
166
167
  },
@@ -1,14 +1,13 @@
1
1
  import { __read } from 'tslib';
2
2
  import sync from 'framesync';
3
- import { useRef, useState, useCallback } from 'react';
4
- import { useUnmountEffect } from './use-unmount-effect.mjs';
3
+ import { useState, useCallback } from 'react';
4
+ import { useIsMounted } from './use-is-mounted.mjs';
5
5
 
6
6
  function useForceUpdate() {
7
- var isUnmountingRef = useRef(false);
7
+ var isMounted = useIsMounted();
8
8
  var _a = __read(useState(0), 2), forcedRenderCount = _a[0], setForcedRenderCount = _a[1];
9
- useUnmountEffect(function () { return (isUnmountingRef.current = true); });
10
9
  var forceRender = useCallback(function () {
11
- !isUnmountingRef.current && setForcedRenderCount(forcedRenderCount + 1);
10
+ isMounted.current && setForcedRenderCount(forcedRenderCount + 1);
12
11
  }, [forcedRenderCount]);
13
12
  /**
14
13
  * Defer this to the end of the next animation frame in case there are multiple
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import { useConstant } from './use-constant.mjs';
3
+
4
+ var counter = 0;
5
+ var incrementId = function () { return counter++; };
6
+ var useId = React.useId
7
+ ? React.useId
8
+ : function () { return useConstant(incrementId); };
9
+
10
+ export { useId };
@@ -0,0 +1,14 @@
1
+ import { useRef, useLayoutEffect } from 'react';
2
+
3
+ function useIsMounted() {
4
+ var isMounted = useRef(false);
5
+ useLayoutEffect(function () {
6
+ isMounted.current = true;
7
+ return function () {
8
+ isMounted.current = false;
9
+ };
10
+ }, []);
11
+ return isMounted;
12
+ }
13
+
14
+ export { useIsMounted };
@@ -5582,6 +5582,12 @@
5582
5582
  hover: makeRenderlessComponent(useHoverGesture),
5583
5583
  };
5584
5584
 
5585
+ var counter = 0;
5586
+ var incrementId = function () { return counter++; };
5587
+ var useId = React__namespace.useId
5588
+ ? React__namespace.useId
5589
+ : function () { return useConstant(incrementId); };
5590
+
5585
5591
  /**
5586
5592
  * When a component is the child of `AnimatePresence`, it can use `usePresence`
5587
5593
  * to access information about whether it's still present in the React tree.
@@ -5612,8 +5618,8 @@
5612
5618
  var isPresent = context.isPresent, onExitComplete = context.onExitComplete, register = context.register;
5613
5619
  // It's safe to call the following hooks conditionally (after an early return) because the context will always
5614
5620
  // either be null or non-null for the lifespan of the component.
5615
- // Replace with useOpaqueId when released in React
5616
- var id = useUniqueId();
5621
+ // Replace with useId when released in React
5622
+ var id = useId();
5617
5623
  React.useEffect(function () { return register(id); }, []);
5618
5624
  var safeToRemove = function () { return onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(id); };
5619
5625
  return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
@@ -5644,9 +5650,6 @@
5644
5650
  function isPresent(context) {
5645
5651
  return context === null ? true : context.isPresent;
5646
5652
  }
5647
- var counter = 0;
5648
- var incrementId = function () { return counter++; };
5649
- var useUniqueId = function () { return useConstant(incrementId); };
5650
5653
 
5651
5654
  function shallowCompare(next, prev) {
5652
5655
  if (!Array.isArray(prev))
@@ -7351,6 +7354,7 @@
7351
7354
  if (isVariantNode && parent && !isControllingVariants) {
7352
7355
  removeFromVariantTree = parent === null || parent === void 0 ? void 0 : parent.addVariantChild(element);
7353
7356
  }
7357
+ values.forEach(function (value, key) { return bindToMotionValue(key, value); });
7354
7358
  parent === null || parent === void 0 ? void 0 : parent.children.add(element);
7355
7359
  element.setProps(props);
7356
7360
  },
@@ -8331,12 +8335,22 @@
8331
8335
  */
8332
8336
  var m = createMotionProxy(createDomMotionConfig);
8333
8337
 
8338
+ function useIsMounted() {
8339
+ var isMounted = React.useRef(false);
8340
+ React.useLayoutEffect(function () {
8341
+ isMounted.current = true;
8342
+ return function () {
8343
+ isMounted.current = false;
8344
+ };
8345
+ }, []);
8346
+ return isMounted;
8347
+ }
8348
+
8334
8349
  function useForceUpdate() {
8335
- var isUnmountingRef = React.useRef(false);
8350
+ var isMounted = useIsMounted();
8336
8351
  var _a = __read(React.useState(0), 2), forcedRenderCount = _a[0], setForcedRenderCount = _a[1];
8337
- useUnmountEffect(function () { return (isUnmountingRef.current = true); });
8338
8352
  var forceRender = React.useCallback(function () {
8339
- !isUnmountingRef.current && setForcedRenderCount(forcedRenderCount + 1);
8353
+ isMounted.current && setForcedRenderCount(forcedRenderCount + 1);
8340
8354
  }, [forcedRenderCount]);
8341
8355
  /**
8342
8356
  * Defer this to the end of the next animation frame in case there are multiple
@@ -8346,16 +8360,10 @@
8346
8360
  return [deferredForceRender, forcedRenderCount];
8347
8361
  }
8348
8362
 
8349
- var presenceId = 0;
8350
- function getPresenceId() {
8351
- var id = presenceId;
8352
- presenceId++;
8353
- return id;
8354
- }
8355
8363
  var PresenceChild = function (_a) {
8356
8364
  var children = _a.children, initial = _a.initial, isPresent = _a.isPresent, onExitComplete = _a.onExitComplete, custom = _a.custom, presenceAffectsLayout = _a.presenceAffectsLayout;
8357
8365
  var presenceChildren = useConstant(newChildrenMap);
8358
- var id = useConstant(getPresenceId);
8366
+ var id = useId();
8359
8367
  var context = React.useMemo(function () { return ({
8360
8368
  id: id,
8361
8369
  initial: initial,
@@ -8407,17 +8415,13 @@
8407
8415
  return new Map();
8408
8416
  }
8409
8417
 
8410
- function getChildKey(child) {
8411
- return child.key || "";
8412
- }
8418
+ var getChildKey = function (child) { return child.key || ""; };
8413
8419
  function updateChildLookup(children, allChildren) {
8414
8420
  var seenChildren = new Set() ;
8415
8421
  children.forEach(function (child) {
8416
8422
  var key = getChildKey(child);
8417
- if (seenChildren) {
8418
- if (seenChildren.has(key)) {
8419
- console.warn("Children of AnimatePresence require unique keys. \"".concat(key, "\" is a duplicate."));
8420
- }
8423
+ if (seenChildren && seenChildren.has(key)) {
8424
+ console.warn("Children of AnimatePresence require unique keys. \"".concat(key, "\" is a duplicate."));
8421
8425
  seenChildren.add(key);
8422
8426
  }
8423
8427
  allChildren.set(key, child);
@@ -8473,29 +8477,34 @@
8473
8477
  var forceRenderLayoutGroup = React.useContext(LayoutGroupContext).forceRender;
8474
8478
  if (forceRenderLayoutGroup)
8475
8479
  forceRender = forceRenderLayoutGroup;
8476
- var isInitialRender = React.useRef(true);
8477
- var isMounted = React.useRef(true);
8478
- React.useEffect(function () { return function () {
8479
- isMounted.current = false;
8480
- }; }, []);
8480
+ var isMounted = useIsMounted();
8481
8481
  // Filter out any children that aren't ReactElements. We can only track ReactElements with a props.key
8482
8482
  var filteredChildren = onlyElements(children);
8483
+ var childrenToRender = filteredChildren;
8484
+ var exiting = new Set();
8483
8485
  // Keep a living record of the children we're actually rendering so we
8484
8486
  // can diff to figure out which are entering and exiting
8485
- var presentChildren = React.useRef(filteredChildren);
8487
+ var presentChildren = React.useRef(childrenToRender);
8486
8488
  // A lookup table to quickly reference components by key
8487
8489
  var allChildren = React.useRef(new Map()).current;
8488
- // A living record of all currently exiting components.
8489
- var exiting = React.useRef(new Set()).current;
8490
- updateChildLookup(filteredChildren, allChildren);
8491
8490
  // If this is the initial component render, just deal with logic surrounding whether
8492
8491
  // we play onMount animations or not.
8493
- if (isInitialRender.current) {
8492
+ var isInitialRender = React.useRef(true);
8493
+ useIsomorphicLayoutEffect(function () {
8494
8494
  isInitialRender.current = false;
8495
- return (React__namespace.createElement(React__namespace.Fragment, null, filteredChildren.map(function (child) { return (React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, initial: initial ? undefined : false, presenceAffectsLayout: presenceAffectsLayout }, child)); })));
8495
+ updateChildLookup(filteredChildren, allChildren);
8496
+ presentChildren.current = childrenToRender;
8497
+ });
8498
+ useUnmountEffect(function () {
8499
+ isInitialRender.current = true;
8500
+ allChildren.clear();
8501
+ exiting.clear();
8502
+ });
8503
+ if (isInitialRender.current) {
8504
+ return (React__namespace.createElement(React__namespace.Fragment, null, childrenToRender.map(function (child) { return (React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, initial: initial ? undefined : false, presenceAffectsLayout: presenceAffectsLayout }, child)); })));
8496
8505
  }
8497
8506
  // If this is a subsequent render, deal with entering and exiting children
8498
- var childrenToRender = __spreadArray([], __read(filteredChildren), false);
8507
+ childrenToRender = __spreadArray([], __read(childrenToRender), false);
8499
8508
  // Diff the keys of the currently-present and target children to update our
8500
8509
  // exiting list.
8501
8510
  var presentKeys = presentChildren.current.map(getChildKey);
@@ -8507,10 +8516,6 @@
8507
8516
  if (targetKeys.indexOf(key) === -1) {
8508
8517
  exiting.add(key);
8509
8518
  }
8510
- else {
8511
- // In case this key has re-entered, remove from the exiting list
8512
- exiting.delete(key);
8513
- }
8514
8519
  }
8515
8520
  // If we currently have exiting children, and we're deferring rendering incoming children
8516
8521
  // until after all current children have exiting, empty the childrenToRender array
@@ -8536,9 +8541,8 @@
8536
8541
  // Defer re-rendering until all exiting children have indeed left
8537
8542
  if (!exiting.size) {
8538
8543
  presentChildren.current = filteredChildren;
8539
- if (isMounted.current === false) {
8544
+ if (isMounted.current === false)
8540
8545
  return;
8541
- }
8542
8546
  forceRender();
8543
8547
  onExitComplete && onExitComplete();
8544
8548
  }
@@ -8551,7 +8555,6 @@
8551
8555
  var key = child.key;
8552
8556
  return exiting.has(key) ? (child) : (React__namespace.createElement(PresenceChild, { key: getChildKey(child), isPresent: true, presenceAffectsLayout: presenceAffectsLayout }, child));
8553
8557
  });
8554
- presentChildren.current = childrenToRender;
8555
8558
  if (exitBeforeEnter &&
8556
8559
  childrenToRender.length > 1) {
8557
8560
  console.warn("You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.");
@@ -9521,13 +9524,15 @@
9521
9524
  });
9522
9525
  React.useEffect(function () {
9523
9526
  element.mount({});
9524
- return element.unmount();
9525
- }, []);
9527
+ return element.unmount;
9528
+ }, [element]);
9526
9529
  React.useEffect(function () {
9527
9530
  element.setProps({
9528
- onUpdate: function (v) { return setAnimationState(__assign({}, v)); },
9531
+ onUpdate: function (v) {
9532
+ setAnimationState(__assign({}, v));
9533
+ },
9529
9534
  });
9530
- });
9535
+ }, [setAnimationState, element]);
9531
9536
  var startAnimation = useConstant(function () { return function (animationDefinition) {
9532
9537
  return animateVisualElement(element, animationDefinition);
9533
9538
  }; });