Skip to content

Commit

Permalink
Fix react-hooks/exhaustive-deps errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvisompura committed Jan 31, 2025
1 parent 644c0e8 commit 765a5cc
Show file tree
Hide file tree
Showing 25 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export const useRegisterWithActionBar = (refs: MutableRefObject<HTMLElement>[])
return () => {
refs.forEach(ref => focusableComponents.delete(ref.current));
};
}, []);
}, [focusableComponents, refs]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const InterpreterActions = (props: PropsWithChildren<InterpreterActionsPr

// Return the cleanup function that will dispose of the event handlers.
return () => disposableStore.dispose();
}, []);
}, [props.runtime.runtimeId, props.runtimeSessionService, session]);

// Interrupt the session, if we have one.
const interrupt = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import './interpreterGroup.css';

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

// Other dependencies.
import { DisposableStore } from '../../../../../base/common/lifecycle.js';
Expand Down Expand Up @@ -38,7 +38,7 @@ export const InterpreterGroup = (props: InterpreterGroupProps) => {
* Determines whether an alternate runtime is alive.
* @returns A value which indicates whether an alternate runtime is alive.
*/
const isAlternateRuntimeAlive = () => {
const isAlternateRuntimeAlive = useCallback(() => {
// Get the active sessions.
const activeSessions = props.runtimeSessionService.activeSessions;

Expand Down Expand Up @@ -66,7 +66,7 @@ export const InterpreterGroup = (props: InterpreterGroupProps) => {

// An alternate runtime is not alive.
return false;
};
}, [props.interpreterGroup.alternateRuntimes, props.runtimeSessionService.activeSessions]);

// State hooks.
const [alternateRuntimeAlive, setAlternateRuntimeAlive] = useState(isAlternateRuntimeAlive());
Expand All @@ -91,7 +91,7 @@ export const InterpreterGroup = (props: InterpreterGroupProps) => {

// Return the cleanup function that will dispose of the event handlers.
return () => disposableStore.dispose();
}, []);
}, [isAlternateRuntimeAlive, props.runtimeSessionService]);

// Render.
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const InterpreterGroups = (props: InterpreterGroupsProps) => {

// Return the cleanup function that will dispose of the event handlers.
return () => disposableStore.dispose();
}, []);
}, [props.languageRuntimeService, props.runtimeAffiliationService]);

// Render.
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const PrimaryInterpreter = (props: PrimaryInterpreterProps) => {

// Return the cleanup function that will dispose of the event handlers.
return () => disposableStore.dispose();
}, []);
}, [props.runtime.runtimeId, props.runtimeSessionService, session]);

// Render.
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const SecondaryInterpreter = (props: SecondaryInterpreterProps) => {

// Return the cleanup function that will dispose of the event handlers.
return () => disposableStore.dispose();
}, []);
}, [props.runtime.runtimeId, props.runtimeSessionService, session]);

// Render.
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const usePositronTopActionBarState = (services: PositronTopActionBarServi

// Return the clean up for our event handlers.
return () => disposableStore.dispose();
}, []);
}, [services.workspaceContextService]);

// Return the Positron top action bar state.
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const ConsoleInstanceInfoModalPopup = (props: ConsoleInstanceInfoModalPopupProps
setSessionState(state);
}));
return () => disposableStore.dispose();
}, []);
}, [props.session]);

const showKernelOutputChannelClickHandler = () => {
props.session.showOutput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const ConsoleInstanceMenuButton = (props: ConsoleInstanceMenuButtonProps)
setActiveRuntimeLabel(labelForSession(e?.session));
}));
return () => disposables.dispose();
}, [positronConsoleContext.activePositronConsoleInstance]);
}, [positronConsoleContext.activePositronConsoleInstance, positronConsoleContext.positronConsoleService]);

// Builds the actions.
const actions = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const HistoryBrowserPopup = (props: HistoryBrowserPopupProps) => {
return () => {
DOM.getActiveWindow().removeEventListener('click', clickHandler);
};
}, [props.selectedIndex]);
}, [props]);

const noMatch = nls.localize('positronConsoleHistoryMatchesEmpty', "No matching history items");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const PositronConsole = (props: PropsWithChildren<PositronConsoleProps>)

// Return the cleanup function that will dispose of the event handlers.
return () => disposableStore.dispose();
}, []);
}, [props.reactComponentContainer]);

// Render.
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const usePositronConsoleState = (services: PositronConsoleServices): Posi

// Return the clean up for our event handlers.
return () => disposableStore.dispose();
}, []);
}, [services.positronConsoleService]);

// Return the Positron console state.
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const ActionBars = (props: PropsWithChildren<ActionBarsProps>) => {

// Return the cleanup function that will dispose of the event handlers.
return () => disposableStore.dispose();
}, []);
}, [props.positronHelpService, props.reactComponentContainer]);

// useEffect for currentHelpEntry.
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { Button } from '../../../../../base/browser/ui/positronComponents/button
* @param props The props for the button
* @return A button with `action` and `action-button` classes added to it.
*/
// eslint-disable-next-line react/prop-types
export function ActionButton({ className, ...props }: React.ComponentProps<typeof Button>) {
return <Button className={`action action-button ${className}`} {...props} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const DynamicPlotThumbnail = (props: DynamicPlotThumbnailProps) => {
props.plotClient.onDidCompleteRender((result) => {
setUri(result.uri);
});
});
}, [props.plotClient]);

// If the plot is not yet rendered yet (no URI), show a placeholder;
// otherwise, show the rendered plot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const OpenInEditorMenuButton = (props: OpenInEditorMenuButtonProps) => {
};
});
setActions(actions);
}, [defaultAction]);
}, [defaultAction, openEditorPlotHandler]);


return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import './positronPlots.css';

// React.
import React, { PropsWithChildren, useEffect, useState } from 'react';
import React, { PropsWithChildren, useCallback, useEffect, useState } from 'react';

// Other dependencies.
import { IWorkbenchLayoutService } from '../../../services/layout/browser/layoutService.js';
Expand Down Expand Up @@ -40,7 +40,7 @@ export interface PositronPlotsProps extends PositronPlotsServices {
export const PositronPlots = (props: PropsWithChildren<PositronPlotsProps>) => {

// Compute the history visibility based on the history policy.
const computeHistoryVisibility = (policy: HistoryPolicy) => {
const computeHistoryVisibility = useCallback((policy: HistoryPolicy) => {
switch (policy) {
case HistoryPolicy.AlwaysVisible:
return true;
Expand All @@ -61,7 +61,7 @@ export const PositronPlots = (props: PropsWithChildren<PositronPlotsProps>) => {
// Show the history.
return true;
}
};
}, [props.positronPlotsService.positronPlotInstances.length, props.reactComponentContainer.height, props.reactComponentContainer.width]);

const zoomHandler = (zoom: number) => {
setZoom(zoom);
Expand Down Expand Up @@ -119,7 +119,7 @@ export const PositronPlots = (props: PropsWithChildren<PositronPlotsProps>) => {

// Return the cleanup function that will dispose of the event handlers.
return () => disposableStore.dispose();
}, []);
}, [computeHistoryVisibility, props.positronPlotsService, props.reactComponentContainer]);

// Render.
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const usePositronPlotsState = (services: PositronPlotsServices): Positron

// Return the clean up for our event handlers.
return () => disposableStore.dispose();
}, []);
}, [services.positronPlotsService]);

return { ...services, positronPlotInstances, selectedInstanceId, selectedInstanceIndex };
};
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const RuntimeClient = (props: runtimeClientProps) => {
return () => {
disposableStore.dispose();
};
}, []);
}, [props.client.clientState, props.client.messageCounter]);

return <tr className='runtime-client'>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const RuntimeClientList = (props: runtimeClientListProps) => {

// Return the cleanup function that will dispose of the event handlers.
return () => disposableStore.dispose();
}, []);
}, [clients, props.session]);

return <div className='runtime-client-list'>
<table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const RuntimeSession = (props: RuntimeSessionProps) => {
setSessionState(state);
}));
return () => disposableStore.dispose();
}, []);
}, [props.session]);

// Render.
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const RuntimeSessionCard = (props: runtimeSessionCardProps) => {
setSessionState(state);
}));
return () => disposableStore.dispose();
}, []);
}, [props.session]);

return (
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const PositronSessions = (props: PropsWithChildren<PositronSessionsProps>

// Return the cleanup function that will dispose of the event handlers.
return () => disposableStore.dispose();
}, []);
}, [props.reactComponentContainer]);

// Render.
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const VariablesInstanceMenuButton = () => {
setActiveRuntimeLabel(labelForRuntime(e?.session));
}));
return () => disposables.dispose();
}, [positronVariablesContext.activePositronVariablesInstance]);
}, [positronVariablesContext.activePositronVariablesInstance, positronVariablesContext.positronVariablesService]);

// Builds the actions.
const actions = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const PositronVariables = (props: PropsWithChildren<PositronVariablesProp

// Return the cleanup function that will dispose of the event handlers.
return () => disposableStore.dispose();
}, []);
}, [props.reactComponentContainer]);

// Render.
return (
Expand Down

0 comments on commit 765a5cc

Please sign in to comment.