8000 fix: fix ref access in React 19 (#6869) · react-bootstrap/react-bootstrap@2c65f5d · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c65f5d

Browse files
authored
fix: fix ref access in React 19 (#6869)
1 parent 8475119 commit 2c65f5d

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"dependencies": {
6161
"@babel/runtime": "^7.24.7",
6262
"@restart/hooks": "^0.4.9",
63-
"@restart/ui": "^1.6.9",
63+
"@restart/ui": "^1.9.0",
6464
"@types/react-transition-group": "^4.4.6",
6565
"classnames": "^2.3.2",
6666
"dom-helpers": "^5.2.1",

src/Collapse.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Transition, {
1010
EXITING,
1111
} from 'react-transition-group/Transition';
1212
import { TransitionCallbacks } from '@restart/ui/types';
13+
import { getChildRef } from '@restart/ui/utils';
1314
import transitionEndListener from './transitionEndListener';
1415
import createChainedFunction from './createChainedFunction';
1516
import triggerBrowserReflow from './triggerBrowserReflow';
@@ -229,7 +230,7 @@ const Collapse = React.forwardRef<Transition<any>, CollapseProps>(
229230
onEntered={handleEntered}
230231
onExit={handleExit}
231232
onExiting={handleExiting}
232-
childRef={(children as any).ref}
233+
childRef={getChildRef(children)}
233234
in={inProp}
234235
timeout={timeout}
235236
mountOnEnter={mountOnEnter}

src/Fade.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Transition, {
88
ENTERING,
99
} from 'react-transition-group/Transition';
1010
import { TransitionCallbacks } from '@restart/ui/types';
11-
import { getReactVersion } from '@restart/ui/utils';
11+
import { getChildRef } from '@restart/ui/utils';
1212
import transitionEndListener from './transitionEndListener';
1313
import triggerBrowserReflow from './triggerBrowserReflow';
1414
import TransitionWrapper from './TransitionWrapper';
@@ -114,16 +114,13 @@ const Fade = React.forwardRef<Transition<any>, FadeProps>(
114114
[onEnter],
115115
);
116116

117-
const { major } = getReactVersion();
118-
const childRef = major >= 19 ? (children as any).props.ref : (children as any).ref;
119-
120117
return (
121118
<TransitionWrapper
122119
ref={ref}
123120
addEndListener={transitionEndListener}
124121
{...props}
125122
onEnter={handleEnter}
126-
childRef={childRef}
123+
childRef={getChildRef(children)}
127124
>
128125
{(status: TransitionStatus, innerProps: Record<string, unknown>) =>
129126
React.cloneElement(children, {

src/OffcanvasToggling.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Transition, {
88
EXITING,
99
} from 'react-transition-group/Transition';
1010
import { TransitionCallbacks } from '@restart/ui/types';
11+
import { getChildRef } from '@restart/ui/utils';
1112
import transitionEndListener from './transitionEndListener';
1213
import { BsPrefixOnlyProps } from './helpers';
1314
import TransitionWrapper from './TransitionWrapper';
@@ -113,7 +114,7 @@ const OffcanvasToggling = React.forwardRef<
113114
unmountOnExit={unmountOnExit}
114115
appear={appear}
115116
{...props}
116-
childRef={(children as any).ref}
117+
childRef={getChildRef(children)}
117118
>
118119
{(status: TransitionStatus, innerProps: Record<string, unknown>) =>
119120
React.cloneElement(children, {

src/OverlayTrigger.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import useTimeout from '@restart/hooks/useTimeout';
66
import warning from 'warning';
77
import { useUncontrolledProp } from 'uncontrollable';
88
import useMergedRefs from '@restart/hooks/useMergedRefs';
9+
import { getChildRef } from '@restart/ui/utils';
910
import Overlay, { OverlayChildren, OverlayProps } from './Overlay';
1011
import safeFindDOMNode from './safeFindDOMNode';
1112
import { Placement } from './types';
@@ -192,7 +193,7 @@ const OverlayTrigger: React.FC<OverlayTriggerProps> = ({
192193
const triggerNodeRef = useRef(null);
193194
const mergedRef = useMergedRefs<unknown>(
194195
triggerNodeRef,
195-
(children as any).ref,
196+
getChildRef(children),
196197
);
197198
const timeout = useTimeout();
198199
const hoverStateRef = useRef<string>('');

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,10 +1897,10 @@
18971897
dependencies:
18981898
dequal "^2.0.3"
18991899

1900-
"@restart/ui@^1.6.9":
1901-
version "1.6.9"
1902-
resolved "https://registry.yarnpkg.com/@restart/ui/-/ui-1.6.9.tgz#05ec905a56486fa39b62f29c09b3917e57acd62f"
1903-
integrity sha512-mUbygUsJcRurjZCt1f77gg4DpheD1D+Sc7J3JjAkysUj7t8m4EBJVOqWC9788Qtbc69cJ+HlJc6jBguKwS8Mcw==
1900+
"@restart/ui@^1.9.0":
1901+
version "1.9.0"
1902+
resolved "https://registry.yarnpkg.com/@restart/ui/-/ui-1.9.0.tgz#11a64bae8b9babac08aafb459da635edff171985"
1903+
integrity sha512-M/k/ILBXbEIFn0wSGuJYqscih7gwMcnVwv44kgHZ344sjLoO2vFK8AtkMGXx2sEANDwxEPoDhjhfIDDvrvCBCA==
19041904
dependencies:
19051905
"@babel/runtime" "^7.21.0"
19061906
"@popperjs/core" "^2.11.6"

0 commit comments

Comments
 (0)
0