@@ -69,15 +69,18 @@ export const PodConnect: React.FCC<PodConnectProps> = ({
6969
7070 const containers = useMemo ( ( ) => _ . keyBy ( _ . get ( obj , 'spec.containers' , [ ] ) , 'name' ) , [ obj ] ) ;
7171
72+ const podName = useMemo ( ( ) => obj . metadata ?. name || '' , [ obj ?. metadata ?. name ] ) ;
73+ const namespace = useMemo ( ( ) => obj . metadata ?. namespace || 'default' , [ obj ?. metadata ?. namespace ] ) ;
74+ // We are being more specific with the dependency array here to avoid additional rerenders when other fields in obj changes
75+ // eslint-disable-next-line react-hooks/exhaustive-deps
76+ const isWindows = useMemo ( ( ) => isWindowsPod ( obj ) , [ obj ?. spec ?. tolerations ] ) ;
77+
7278 const connect = useCallback ( ( ) => {
73- const {
74- metadata : { name, namespace } ,
75- } = obj ;
7679 const usedClient = isOpenShift ? 'oc' : 'kubectl' ;
77- const command = isWindowsPod ( obj ) ? [ 'cmd' ] : [ 'sh' , '-i' , '-c' , 'TERM=xterm sh' ] ;
80+ const command = isWindows ? [ 'cmd' ] : [ 'sh' , '-i' , '-c' , 'TERM=xterm sh' ] ;
7881 const params = {
7982 ns : namespace ,
80- name,
83+ name : podName ,
8184 path : attach ? ATTACH_COMMAND : EXEC_COMMAND ,
8285 queryParams : {
8386 stdout : '1' ,
@@ -100,7 +103,7 @@ export const PodConnect: React.FCC<PodConnectProps> = ({
100103 const subprotocols = impersonate . subprotocols . concat ( 'base64.channel.k8s.io' ) ;
101104
102105 let previous = '' ;
103- wsRef . current = new WSFactory ( `${ name } -terminal` , {
106+ wsRef . current = new WSFactory ( `${ podName } -terminal` , {
104107 host : 'auto' ,
105108 reconnect : true ,
106109 path : resourceURL ( PodModel , params ) ,
@@ -141,7 +144,7 @@ export const PodConnect: React.FCC<PodConnectProps> = ({
141144 } )
142145 // eslint-disable-next-line no-console
143146 . onerror ( ( evt : any ) => console . error ( `WS error?! ${ evt } ` ) ) ;
144- } , [ obj , attach , activeContainer , t , isOpenShift ] ) ;
147+ } , [ podName , namespace , isWindows , attach , activeContainer , t , isOpenShift ] ) ;
145148
146149 // Connect on mount and when dependencies change
147150 useEffect ( ( ) => {
0 commit comments