fix: Date.now() called causing crazy rerenders (#1057)

Fixes HDX-2185

Credit to @MikeShi42
This commit is contained in:
Aaron Knudtson 2025-08-08 18:57:59 +05:30 committed by GitHub
parent 82a31194e4
commit 7cd1d2a2ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
"@hyperdx/app": patch
---
fix: endless rerenders caused by Date.now() in a component

View file

@ -15,6 +15,9 @@ export interface ILanguageFormatter {
formatKeyValPair: (key: string, value: string) => string;
}
// Defined outside of the component to fix rerenders
const NOW = Date.now();
export function useAutoCompleteOptions(
formatter: ILanguageFormatter,
value: string,
@ -94,10 +97,7 @@ export function useAutoCompleteOptions(
where: '',
// TODO: Pull in date for query as arg
// just assuming 1/2 day is okay to query over right now
dateRange: [
new Date(Date.now() - (86400 * 1000) / 2),
new Date(Date.now()),
],
dateRange: [new Date(NOW - (86400 * 1000) / 2), new Date(NOW)],
}));
const { data: keyVals } = useGetKeyValues({
chartConfigs,