Skip to content

Commit 815e642

Browse files
authored
chore: add lint rules to treat missing hook dependencies as errors (#1420)
Tested on each of the spots that had hooks that were changed, seems good
1 parent 991bd7e commit 815e642

25 files changed

Lines changed: 154 additions & 105 deletions

.changeset/sweet-houses-scream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/app": patch
3+
---
4+
5+
chore: treat missing react hook dependencies as errors

packages/app/.eslintrc.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
module.exports = {
22
root: true,
33
parser: '@typescript-eslint/parser',
4-
plugins: ['simple-import-sort', '@typescript-eslint', 'prettier'],
4+
plugins: [
5+
'simple-import-sort',
6+
'@typescript-eslint',
7+
'prettier',
8+
'react-hooks',
9+
],
510
parserOptions: {
611
tsconfigRootDir: __dirname,
712
project: ['./tsconfig.json'],
@@ -23,6 +28,7 @@ module.exports = {
2328
'react/display-name': 'off',
2429
'simple-import-sort/exports': 'error',
2530
'simple-import-sort/imports': 'error',
31+
'react-hooks/exhaustive-deps': 'error',
2632
'no-console': ['error', { allow: ['warn', 'error'] }],
2733
},
2834
overrides: [

packages/app/src/AppNav.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) {
363363
isLoading: isLogViewsLoading,
364364
refetch: refetchLogViews,
365365
} = useSavedSearches();
366-
const logViews = logViewsData ?? [];
366+
const logViews = useMemo(() => logViewsData ?? [], [logViewsData]);
367367

368368
const updateDashboard = useUpdateDashboard();
369369
const updateLogView = useUpdateSavedSearch();
@@ -373,7 +373,7 @@ export default function AppNav({ fixed = false }: { fixed?: boolean }) {
373373
isLoading: isDashboardsLoading,
374374
refetch: refetchDashboards,
375375
} = useDashboards();
376-
const dashboards = dashboardsData ?? [];
376+
const dashboards = useMemo(() => dashboardsData ?? [], [dashboardsData]);
377377

378378
const router = useRouter();
379379
const { pathname, query } = router;

packages/app/src/BenchmarkPage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ function BenchmarkPage() {
176176
) {
177177
return;
178178
}
179-
setQueries(data.queries);
180-
setConnections(data.connections);
179+
setQueries(data.queries || []);
180+
setConnections(data.connections || []);
181181
setIterations(data.iterations);
182182
};
183183

184-
const _queries = queries || [];
185-
const _connections = connections || [];
184+
const _queries = useMemo(() => queries || [], [queries]);
185+
const _connections = useMemo(() => connections || [], [connections]);
186186

187187
const { data: estimates } = useEstimates(
188188
{ queries: _queries, connections: _connections },

packages/app/src/DBDashboardPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ const Tile = forwardRef(
149149
.getElementById(`chart-${chart.id}`)
150150
?.scrollIntoView({ behavior: 'smooth' });
151151
}
152-
}, []);
152+
}, [chart.id, isHighlighed]);
153153

154154
const [queriedConfig, setQueriedConfig] = useState<
155155
ChartConfigWithDateRange | undefined
@@ -776,6 +776,7 @@ function DBDashboardPage({ presetConfig }: { presetConfig?: Dashboard }) {
776776
where,
777777
whereLanguage,
778778
onTimeRangeSelect,
779+
filterQueries,
779780
],
780781
);
781782

packages/app/src/DBSearchPage.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ function useSearchedConfigToChartConfig({
530530
where,
531531
whereLanguage,
532532
defaultOrderBy,
533+
orderBy,
533534
]);
534535
}
535536

@@ -1072,7 +1073,7 @@ function DBSearchPage() {
10721073
...chartConfig,
10731074
dateRange: searchedTimeRange,
10741075
};
1075-
}, [me?.team, chartConfig, searchedTimeRange]);
1076+
}, [chartConfig, searchedTimeRange]);
10761077

10771078
const displayedColumns = splitAndTrimWithBracket(
10781079
dbSqlRowTableConfig?.select ??
@@ -1243,7 +1244,7 @@ function DBSearchPage() {
12431244
onTimeRangeSelect(d1, d2);
12441245
setIsLive(false);
12451246
},
1246-
[onTimeRangeSelect],
1247+
[onTimeRangeSelect, setIsLive],
12471248
);
12481249

12491250
const filtersChartConfig = useMemo<ChartConfigWithDateRange>(() => {

packages/app/src/DOMPlayer.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export default function DOMPlayer({
243243
}, [setPlayerTime]);
244244

245245
const updatePlayerTimeRafRef = useRef(0);
246-
const updatePlayerTime = () => {
246+
const updatePlayerTime = useCallback(() => {
247247
if (
248248
replayer.current != null &&
249249
replayer.current.service.state.matches('playing')
@@ -257,15 +257,15 @@ export default function DOMPlayer({
257257
}
258258

259259
updatePlayerTimeRafRef.current = requestAnimationFrame(updatePlayerTime);
260-
};
260+
}, []);
261261

262262
// Update timestamp ui in timeline
263263
useEffect(() => {
264264
updatePlayerTimeRafRef.current = requestAnimationFrame(updatePlayerTime);
265265
return () => {
266266
cancelAnimationFrame(updatePlayerTimeRafRef.current);
267267
};
268-
}, []);
268+
}, [updatePlayerTime]);
269269

270270
// Manage playback pause/play state, rrweb only
271271
useEffect(() => {
@@ -398,6 +398,7 @@ export default function DOMPlayer({
398398
isInitialEventsLoaded,
399399
playerState,
400400
play,
401+
debug,
401402
]);
402403

403404
// Set player to the correct time based on focus
@@ -440,7 +441,7 @@ export default function DOMPlayer({
440441
}
441442
abort();
442443
};
443-
}, []);
444+
}, [abort]);
444445

445446
const isLoading = isInitialEventsLoaded === false && isSearchResultsFetching;
446447
// TODO: Handle when ts is set to a value that's outside of this session

packages/app/src/Playbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function Playbar({
3636
queryKey: ['PlayBar', queriedConfig],
3737
},
3838
);
39-
const events: any[] = data?.data ?? [];
39+
const events: any[] = useMemo(() => data?.data ?? [], [data?.data]);
4040

4141
const markers = useMemo<PlaybarMarker[]>(() => {
4242
return uniqBy(

packages/app/src/PodDetailsSidePanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ export default function PodDetailsSidePanel({
320320
}
321321
return _where;
322322
}, [
323-
nodeName,
324323
logSource,
325324
doesPrimaryOrSortingKeysContainServiceExpression,
326325
logServiceNames,
326+
podName,
327327
]);
328328

329329
const handleClose = React.useCallback(() => {

packages/app/src/ServicesDashboardPage.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,13 @@ function ServicesDashboardPage() {
906906
) {
907907
onSubmit();
908908
}
909-
}, [service, sourceId]);
909+
}, [
910+
service,
911+
sourceId,
912+
appliedConfig.service,
913+
appliedConfig.source,
914+
onSubmit,
915+
]);
910916

911917
return (
912918
<Box p="sm">

0 commit comments

Comments
 (0)