Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix room list being laggy while scrolling 🐌 #7939

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/components/views/elements/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export default class Tooltip extends React.Component<ITooltipProps> {
});
}

// Add the parent's position to the tooltips, so it's correctly
// positioned, also taking into account any window zoom
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this comment up to describe the function instead of in the usage where the context can get lost when you're just focusing on the updatePosition code

private updatePosition(style: CSSProperties) {
const parentBox = this.parent.getBoundingClientRect();
let offset = 0;
Expand Down Expand Up @@ -155,11 +157,12 @@ export default class Tooltip extends React.Component<ITooltipProps> {
}

private renderTooltip = () => {
// Add the parent's position to the tooltips, so it's correctly
// positioned, also taking into account any window zoom
// NOTE: The additional 6 pixels for the left position, is to take account of the
// tooltips chevron
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the extra 6 pixels note because that is no longer relevant since the tooltip positioning was made to be relative to the element itself, see #7551

const style = this.updatePosition({});
let style: CSSProperties = {};
// When the tooltip is hidden, no need to thrash the DOM with `style`
// attribute updates (performance)
if (this.props.visible) {
style = this.updatePosition({});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only update the style attribute of actually visible tooltips. No need to waste resources on hidden tooltips.

// Hide the entire container when not visible. This prevents flashing of the tooltip
// if it is not meant to be visible on first mount.
style.display = this.props.visible ? "block" : "none";
Expand Down
24 changes: 14 additions & 10 deletions src/components/views/elements/TooltipTarget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ const TooltipTarget: React.FC<IProps> = ({
const show = () => setIsVisible(true);
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
const hide = () => setIsVisible(false);

// No need to fill up the DOM with hidden tooltip elements. Only add the
// tooltip when we're hovering over the item (performance)
const tooltip = isVisible && <Tooltip
id={id}
className={className}
tooltipClassName={tooltipClassName}
label={label}
yOffset={yOffset}
alignment={alignment}
visible={isVisible}
maxParentWidth={maxParentWidth}
/>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add DOM elements to the page for hidden tooltips.

This is the same pattern that we use in src/components/views/elements/AccessibleTooltipButton.tsx#L75-L80


Previously, we just had a bunch of hidden This room is public tooltips from the decorated avatars in the room list, src/components/views/avatars/DecoratedRoomAvatar.tsx#L190-L196, even though no tooltips were actually being shown on the page.


return (
<div
tabIndex={0}
Expand All @@ -56,16 +69,7 @@ const TooltipTarget: React.FC<IProps> = ({
{...rest}
>
{ children }
<Tooltip
id={id}
className={className}
tooltipClassName={tooltipClassName}
label={label}
yOffset={yOffset}
alignment={alignment}
visible={isVisible}
maxParentWidth={maxParentWidth}
/>
{ tooltip }
</div>
);
};
Expand Down
4 changes: 3 additions & 1 deletion test/components/views/elements/TooltipTarget-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ describe('<TooltipTarget />', () => {
afterEach(() => {
// clean up visible tooltips
const tooltipWrapper = document.querySelector('.mx_Tooltip_wrapper');
document.body.removeChild(tooltipWrapper);
if (tooltipWrapper) {
document.body.removeChild(tooltipWrapper);
}
});

it('renders container', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,5 @@ exports[`<TooltipTarget /> renders container 1`] = `
<span>
child
</span>
<div
class="test className"
/>
Copy link
Contributor Author

@MadLittleMods MadLittleMods Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we selectively render <Tooltip> now, the tooltip "placeholder" is no longer visible when the tooltip is not visible.

</div>
`;