Skip to content

Commit

Permalink
Minor code changes
Browse files Browse the repository at this point in the history
Remove component memoization, it didn't work anyway and doesn't seem needed. We don't have anything particularly expensive to render here from React's perspective.
  • Loading branch information
gzdunek committed Feb 24, 2025
1 parent 836a191 commit efee9e5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
5 changes: 3 additions & 2 deletions web/packages/teleport/src/DesktopSession/DesktopSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';

import { Box, ButtonPrimary, ButtonSecondary, Flex, Indicator } from 'design';
import { Info } from 'design/Alert';
Expand Down Expand Up @@ -272,7 +272,8 @@ export function DesktopSession(props: State) {
if (!client) {
return;
}
const setResolution = tdpClientCanvasRef.current?.setResolution;
const setResolution = (spec: ClientScreenSpec) =>
tdpClientCanvasRef.current?.setResolution(spec);
client.addListener(TdpClientEvent.TDP_CLIENT_SCREEN_SPEC, setResolution);

return () => {
Expand Down
3 changes: 2 additions & 1 deletion web/packages/teleport/src/Player/DesktopPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import { TdpClientCanvasRef } from 'teleport/components/TdpClientCanvas/TdpClien
import cfg from 'teleport/config';
import { formatDisplayTime, StatusEnum } from 'teleport/lib/player';
import { PlayerClient, TdpClientEvent } from 'teleport/lib/tdp';
import type { ClientScreenSpec } from 'teleport/lib/tdp/codec';
import { BitmapFrame } from 'teleport/lib/tdp/client';
import type { ClientScreenSpec, PngFrame } from 'teleport/lib/tdp/codec';
import { getHostName } from 'teleport/services/api';

import ProgressBar from './ProgressBar';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import React, {
forwardRef,
memo,
useEffect,
useImperativeHandle,
useRef,
Expand All @@ -42,7 +41,27 @@ export interface TdpClientCanvasRef {
focus(): void;
}

const TdpClientCanvas = forwardRef<TdpClientCanvasRef, Props>((props, ref) => {
export const TdpClientCanvas = forwardRef<
TdpClientCanvasRef,
{
onKeyDown?(e: React.KeyboardEvent): void;
onKeyUp?(e: React.KeyboardEvent): void;
onBlur?(e: React.FocusEvent): void;
onMouseMove?(e: React.MouseEvent): void;
onMouseDown?(e: React.MouseEvent): void;
onMouseUp?(e: React.MouseEvent): void;
onMouseWheel?(e: WheelEvent): void;
onContextMenu?(e: React.MouseEvent): void;
/**
* Handles canvas resize events.
*
* This function is called whenever the canvas is resized,
* with a debounced delay of 250 ms to optimize performance.
*/
onResize?(e: { width: number; height: number }): void;
style?: CSSProperties;
}
>((props, ref) => {
const {
onKeyDown,
onKeyUp,
Expand Down Expand Up @@ -141,25 +160,6 @@ const TdpClientCanvas = forwardRef<TdpClientCanvasRef, Props>((props, ref) => {
);
});

export type Props = {
onKeyDown?(e: React.KeyboardEvent): void;
onKeyUp?(e: React.KeyboardEvent): void;
onBlur?(e: React.FocusEvent): void;
onMouseMove?(e: React.MouseEvent): void;
onMouseDown?(e: React.MouseEvent): void;
onMouseUp?(e: React.MouseEvent): void;
onMouseWheel?(e: WheelEvent): void;
onContextMenu?(e: React.MouseEvent): void;
/**
* Handles canvas resize events.
*
* This function is called whenever the canvas is resized,
* with a debounced delay of 250 ms to optimize performance.
*/
onResize?(e: { width: number; height: number }): void;
style?: CSSProperties;
};

interface Pointer {
data: ImageData | boolean;
hotspot_x?: number;
Expand Down Expand Up @@ -240,5 +240,3 @@ function makeBitmapFrameRenderer(

return frame => bitmapBuffer.push(frame);
}

export default memo(TdpClientCanvas);
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import TdpClientCanvas from './TdpClientCanvas';
import { TdpClientCanvas } from './TdpClientCanvas';

export default TdpClientCanvas;

0 comments on commit efee9e5

Please sign in to comment.