[Observability overview] Fix overview page duplicate requests#125204
[Observability overview] Fix overview page duplicate requests#125204shahzad31 merged 2 commits intoelastic:mainfrom
Conversation
💚 Build SucceededMetrics [docs]Async chunks
To update your PR or re-run it, just comment with: cc @shahzad31 |
| const bucketSize = calculateBucketSize({ | ||
| start: absoluteTime.start, | ||
| end: absoluteTime.end, | ||
| }); | ||
|
|
||
| const bucketSizeValue = useMemo(() => { | ||
| if (bucketSize?.bucketSize) { | ||
| return { | ||
| bucketSize: bucketSize.bucketSize, | ||
| intervalString: bucketSize.intervalString, | ||
| }; | ||
| } | ||
| }, [bucketSize?.bucketSize, bucketSize?.intervalString]); | ||
|
|
There was a problem hiding this comment.
I'm not sure that useMemo is the best option here. bucketSize and bucketSizeValue are exactly the same value and I don't think it reflects the intentions of what we want to achieve, which could lead to confusion and bugs in the future.
bucketSize should probably be part of the state of the component and we should only update it when absoluteTime.start or absoluteTime.end change, preventing unnecessary rerenders.
What do you think about something like this:
| const bucketSize = calculateBucketSize({ | |
| start: absoluteTime.start, | |
| end: absoluteTime.end, | |
| }); | |
| const bucketSizeValue = useMemo(() => { | |
| if (bucketSize?.bucketSize) { | |
| return { | |
| bucketSize: bucketSize.bucketSize, | |
| intervalString: bucketSize.intervalString, | |
| }; | |
| } | |
| }, [bucketSize?.bucketSize, bucketSize?.intervalString]); | |
| const [bucketSize, setBucketSize] = useState(undefined); | |
| useEffect(() => { | |
| const bucket = calculateBucketSize({ | |
| start: absoluteTime.start, | |
| end: absoluteTime.end, | |
| }); | |
| setBucketSize(bucket); | |
| }, [absoluteTime.start, absoluteTime.end]) | |
There was a problem hiding this comment.
i think absolute time start and end changes whenever component re-renders , so can't use those in side effect
There was a problem hiding this comment.
I see... I wasn't expecting it 🙃
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Summary
Fixes #125200
Wrap bucketsize value in useMemo, since it was triggering unnecessary re-renders.