Skip to content

Commit 409d0c4

Browse files
Merge pull request #15745 from logonoff/OCPBUGS-65776-pod-connect
OCPBUGS-65776: Fix unnecessary rerenders with pod-connect
2 parents 802f366 + a1982e0 commit 409d0c4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

frontend/public/components/pod-connect.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,18 @@ export const PodConnect: React.FCC<PodConnectProps> = ({
7171

7272
const containers = useMemo(() => _.keyBy(_.get(obj, 'spec.containers', []), 'name'), [obj]);
7373

74+
const podName = useMemo(() => obj.metadata?.name || '', [obj?.metadata?.name]);
75+
const namespace = useMemo(() => obj.metadata?.namespace || 'default', [obj?.metadata?.namespace]);
76+
// We are being more specific with the dependency array here to avoid additional rerenders when other fields in obj changes
77+
// eslint-disable-next-line react-hooks/exhaustive-deps
78+
const isWindows = useMemo(() => isWindowsPod(obj), [obj?.spec?.tolerations]);
79+
7480
const connect = useCallback(() => {
75-
const {
76-
metadata: { name, namespace },
77-
} = obj;
7881
const usedClient = isOpenShift ? 'oc' : 'kubectl';
79-
const command = isWindowsPod(obj) ? ['cmd'] : ['sh', '-i', '-c', 'TERM=xterm sh'];
82+
const command = isWindows ? ['cmd'] : ['sh', '-i', '-c', 'TERM=xterm sh'];
8083
const params = {
8184
ns: namespace,
82-
name,
85+
name: podName,
8386
path: attach ? ATTACH_COMMAND : EXEC_COMMAND,
8487
queryParams: {
8588
stdout: '1',
@@ -102,7 +105,7 @@ export const PodConnect: React.FCC<PodConnectProps> = ({
102105
const subprotocols = impersonate.subprotocols.concat('base64.channel.k8s.io');
103106

104107
let previous = '';
105-
wsRef.current = new WSFactory(`${name}-terminal`, {
108+
wsRef.current = new WSFactory(`${podName}-terminal`, {
106109
host: 'auto',
107110
reconnect: true,
108111
path: resourceURL(PodModel, params),
@@ -143,7 +146,7 @@ export const PodConnect: React.FCC<PodConnectProps> = ({
143146
})
144147
// eslint-disable-next-line no-console
145148
.onerror((evt: any) => console.error(`WS error?! ${evt}`));
146-
}, [obj, attach, activeContainer, t, isOpenShift]);
149+
}, [podName, namespace, isWindows, attach, activeContainer, t, isOpenShift]);
147150

148151
// Connect on mount and when dependencies change
149152
useEffect(() => {

0 commit comments

Comments
 (0)