-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug fix] Trace analytics scroll bar reset #1917
Conversation
Signed-off-by: Adam Tackett <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
setTimeout(() => { | ||
spanContainerRef.current.scrollTop = prevScrollPositionRef.current || 0; | ||
}, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: why do we need setTimeout
with delay 0 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without it, closing the fly-out will reset the scroll bar. I believe this happens because the fly-out table closing behavior is handled in span_detail_table and it needs a delay for the use-effect.
This fix results in a slight flicker as the scroll bar adjust after being rendered to the correct position. I have not been able to find a fix that prevents this. Have tried using useMemo as it is handled in the SpanList menu but the click event for Timeline is happening in a different area. |
scrollbar resetting on rerender is not normal behavior, it might be caused by the plot rerendering. if recovering scroll position flickers, you can try to memorize the plot component instead |
I see that we rely on a memo for generating the span list and inject that value directly, but I wonder why we need a memo at all? Can we use the spans as JSX and let React do the rendering? I suspect that memo is where the reset is sneaking in to begin with. |
i don't think the span list is relevant for this bug, since triggering the bug doesn't need user to go to the span list view, that component was never mounted |
Ah, got confused between this being the span view as a whole and there being a timeline option under the span view. But the same thing applies to the timeline, both of them are being memoized. |
the gantt chart is not memorized, memorizing it could workaround this bug. you can try adding this above const ganttChart = useMemo(
() => (
<Plt
data={data.gantt}
layout={layout}
onClickHandler={onClick}
onHoverHandler={onHover}
onUnhoverHandler={onUnhover}
/>
),
[data.gantt, layout]
); and change dashboards-observability/public/components/trace_analytics/components/traces/span_detail_panel.tsx Lines 296 to 306 in 4fa3705
to {toggleIdSelected === 'timeline' ? ganttChart : spanDetailTable} |
Signed-off-by: Adam Tackett <[email protected]>
Implemented Josh's suggestion and tested. All working correctly. |
for completeness and good practice, the dependency array should include all dependencies. so the correct way would be using const onClick = useCallback(
(event: any) => {
if (!event?.points) return;
const point = event.points[0];
if (fromApp) {
props.openSpanFlyout(point.data.spanId);
} else {
setCurrentSpan(point.data.spanId);
}
},
[props.openSpanFlyout, setCurrentSpan, fromApp]
); const onHover = useCallback(() => {
const dragLayer = document.getElementsByClassName('nsewdrag')?.[0];
dragLayer.style.cursor = 'pointer';
}, []);
const onUnhover = useCallback(() => {
const dragLayer = document.getElementsByClassName('nsewdrag')?.[0];
dragLayer.style.cursor = '';
}, []); and put them in the dependency array const ganttChart = useMemo(
() => (
<Plt
data={data.gantt}
layout={layout}
onClickHandler={onClick}
onHoverHandler={onHover}
onUnhoverHandler={onUnhover}
/>
),
[data.gantt, layout, onClick, onHover, onUnhover]
); some functions like it likely won't make a real difference, since |
Signed-off-by: Adam Tackett <[email protected]>
The backport to
To backport manually, run these commands in your terminal: # Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/dashboards-observability/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/dashboards-observability/backport-2.x
# Create a new branch
git switch --create backport/backport-1917-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 cc193f6665f0f6a87846cd15016346f030a32545
# Push it to GitHub
git push --set-upstream origin backport/backport-1917-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/dashboards-observability/backport-2.x Then, create a pull request where the |
* Bugfix: Remember scroll bar position on opening flyout. Signed-off-by: Adam Tackett <[email protected]> * Memorize the gnatt chart, fixes flicker Signed-off-by: Adam Tackett <[email protected]> * useCallback added to click actions Signed-off-by: Adam Tackett <[email protected]> --------- Signed-off-by: Adam Tackett <[email protected]> Co-authored-by: Adam Tackett <[email protected]> (cherry picked from commit cc193f6) Signed-off-by: Adam Tackett <[email protected]>
Signed-off-by: Adam Tackett <[email protected]> Co-authored-by: Adam Tackett <[email protected]> (cherry picked from commit cc193f6)
Description
This change resets the scroll bar to the position it was at prior to opening the fly-out.
Issues Resolved
#1916
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.