@skyscanner/backpack-web 43.0.0-dev-v28222480725.1 → 43.1.0
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.
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import { cloneElement, useCallback, useRef } from 'react';
|
|
19
|
+
import { cloneElement, useCallback, useRef, version } from 'react';
|
|
20
20
|
// @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
|
|
21
21
|
import assign from 'object-assign';
|
|
22
22
|
import CSSTransition from 'react-transition-group/CSSTransition';
|
|
@@ -25,15 +25,18 @@ import CSSTransition from 'react-transition-group/CSSTransition';
|
|
|
25
25
|
// It will use the native implementation if it's present and isn't buggy.
|
|
26
26
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
27
27
|
Object.assign = assign;
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
// Assigns a node to the child's own ref, supporting both callback refs and
|
|
29
|
+
// object refs (e.g. createRef). nodeRef is handled separately below since it is
|
|
30
|
+
// always an object ref we own.
|
|
31
|
+
const assignChildRef = (childRef, node) => {
|
|
32
|
+
if (!childRef) {
|
|
30
33
|
return;
|
|
31
34
|
}
|
|
32
|
-
if (typeof
|
|
33
|
-
|
|
35
|
+
if (typeof childRef === 'function') {
|
|
36
|
+
childRef(node);
|
|
34
37
|
} else {
|
|
35
38
|
// eslint-disable-next-line no-param-reassign
|
|
36
|
-
|
|
39
|
+
childRef.current = node;
|
|
37
40
|
}
|
|
38
41
|
};
|
|
39
42
|
|
|
@@ -47,11 +50,12 @@ const TransitionInitialMount = ({
|
|
|
47
50
|
}) => {
|
|
48
51
|
const nodeRef = useRef(null);
|
|
49
52
|
// Read the child's own ref so injecting nodeRef does not clobber it.
|
|
50
|
-
// React 19 exposes ref as a normal prop (children.props.ref)
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
const
|
|
53
|
+
// React 19 exposes ref as a normal prop (children.props.ref) and logs a
|
|
54
|
+
// deprecation warning if you read element.ref; React 18 keeps it on the
|
|
55
|
+
// element itself. Pick the source by major version so we never touch
|
|
56
|
+
// element.ref on React 19, even when the child has no ref of its own.
|
|
57
|
+
const isReact19OrLater = parseInt(version, 10) >= 19;
|
|
58
|
+
const childRef = isReact19OrLater ? children.props.ref : children.ref;
|
|
55
59
|
|
|
56
60
|
// Compose the nodeRef CSSTransition needs with any ref the child already has,
|
|
57
61
|
// so injecting nodeRef does not clobber the child's own ref (e.g. the
|
|
@@ -59,8 +63,8 @@ const TransitionInitialMount = ({
|
|
|
59
63
|
// Memoised so the callback ref keeps a stable identity across renders and is
|
|
60
64
|
// only re-run when nodeRef or the child's ref actually changes.
|
|
61
65
|
const mergedRef = useCallback(node => {
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
nodeRef.current = node;
|
|
67
|
+
assignChildRef(childRef, node);
|
|
64
68
|
}, [childRef]);
|
|
65
69
|
return /*#__PURE__*/_jsx(CSSTransition, {
|
|
66
70
|
nodeRef: nodeRef,
|