Skip to content

Commit 195337d

Browse files
authored
Pass nodeRef to CSSTransition to avoid ReactDOM.findDOMNode (#28339)
Signed-off-by: Michael Telatynski <[email protected]>
1 parent 4bb9f2e commit 195337d

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/components/views/messages/MImageBody.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
6161

6262
private unmounted = true;
6363
private image = createRef<HTMLImageElement>();
64+
private placeholder = createRef<HTMLDivElement>();
6465
private timeout?: number;
6566
private sizeWatcher?: string;
6667

@@ -453,7 +454,11 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
453454
"mx_MImageBody_placeholder--blurhash": this.props.mxEvent.getContent().info?.[BLURHASH_FIELD],
454455
});
455456

456-
placeholder = <div className={classes}>{this.getPlaceholder(maxWidth, maxHeight)}</div>;
457+
placeholder = (
458+
<div className={classes} ref={this.placeholder}>
459+
{this.getPlaceholder(maxWidth, maxHeight)}
460+
</div>
461+
);
457462
}
458463

459464
let showPlaceholder = Boolean(placeholder);
@@ -499,8 +504,19 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
499504
if (!this.props.forExport) {
500505
placeholder = (
501506
<SwitchTransition mode="out-in">
502-
<CSSTransition classNames="mx_rtg--fade" key={`img-${showPlaceholder}`} timeout={300}>
503-
{showPlaceholder ? placeholder : <></> /* Transition always expects a child */}
507+
<CSSTransition
508+
classNames="mx_rtg--fade"
509+
key={`img-${showPlaceholder}`}
510+
timeout={300}
511+
nodeRef={this.placeholder}
512+
>
513+
{
514+
showPlaceholder ? (
515+
placeholder
516+
) : (
517+
<div ref={this.placeholder} />
518+
) /* Transition always expects a child */
519+
}
504520
</CSSTransition>
505521
</SwitchTransition>
506522
);

src/components/views/rooms/RoomBreadcrumbs.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9-
import React from "react";
9+
import React, { createRef } from "react";
1010
import { Room } from "matrix-js-sdk/src/matrix";
1111
import { CSSTransition } from "react-transition-group";
1212

@@ -61,6 +61,7 @@ const RoomBreadcrumbTile: React.FC<{ room: Room; onClick: (ev: ButtonEvent) => v
6161

6262
export default class RoomBreadcrumbs extends React.PureComponent<IProps, IState> {
6363
private isMounted = true;
64+
private toolbar = createRef<HTMLDivElement>();
6465

6566
public constructor(props: IProps) {
6667
super(props);
@@ -113,8 +114,18 @@ export default class RoomBreadcrumbs extends React.PureComponent<IProps, IState>
113114
if (tiles.length > 0) {
114115
// NOTE: The CSSTransition timeout MUST match the timeout in our CSS!
115116
return (
116-
<CSSTransition appear={true} in={this.state.doAnimation} timeout={640} classNames="mx_RoomBreadcrumbs">
117-
<Toolbar className="mx_RoomBreadcrumbs" aria-label={_t("room_list|breadcrumbs_label")}>
117+
<CSSTransition
118+
appear={true}
119+
in={this.state.doAnimation}
120+
timeout={640}
121+
classNames="mx_RoomBreadcrumbs"
122+
nodeRef={this.toolbar}
123+
>
124+
<Toolbar
125+
className="mx_RoomBreadcrumbs"
126+
aria-label={_t("room_list|breadcrumbs_label")}
127+
ref={this.toolbar}
128+
>
118129
{tiles.slice(this.state.skipFirst ? 1 : 0)}
119130
</Toolbar>
120131
</CSSTransition>

0 commit comments

Comments
 (0)