Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: minor fix in tooltip rendering (#10175)

Abhi kumar9443c4233450
diff --git a/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/TooltipPlugin.styles.scss b/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/TooltipPlugin.styles.scss
index a17a19dfa2..b8f4cb3c02 100644
--- a/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/TooltipPlugin.styles.scss
+++ b/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/TooltipPlugin.styles.scss
@@ -6,6 +6,7 @@
border-radius: 4px;
position: fixed;
overflow: auto;
+ transform: translate(-1000px, -1000px); // hide the tooltip initially
&.pinned {
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
diff --git a/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/TooltipPlugin.tsx b/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/TooltipPlugin.tsx
index 1583d4f0f9..72e6e9d651 100644
--- a/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/TooltipPlugin.tsx
+++ b/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/TooltipPlugin.tsx
@@ -42,6 +42,7 @@ export default function TooltipPlugin({
const containerRef = useRef<HTMLDivElement>(null);
const portalRoot = useRef<HTMLElement>(document.body);
const rafId = useRef<number | null>(null);
+ const dismissTimeoutId = useRef<ReturnType<typeof setTimeout> | null>(null);
const layoutRef = useRef<TooltipLayoutInfo>();
const renderRef = useRef(render);
renderRef.current = render;
@@ -167,8 +168,8 @@ export default function TooltipPlugin({
// Push the latest controller state into React so the tooltip's
// DOM representation catches up with the interaction state.
function performRender(): void {
- controller.renderScheduled = false;
rafId.current = null;
+ dismissTimeoutId.current = null;
if (controller.pendingPinnedUpdate) {
applyPinnedSideEffects();
@@ -184,22 +185,40 @@ export default function TooltipPlugin({
});
}
+ // Cancel any pending render to prevent race conditions
+ function cancelPendingRender(): void {
+ if (rafId.current != null) {
+ cancelAnimationFrame(rafId.current);
+ rafId.current = null;
+ }
+ if (dismissTimeoutId.current != null) {
+ clearTimeout(dismissTimeoutId.current);
+ dismissTimeoutId.current = null;
+ }
+ }
+
// Throttle React re-renders:
// - use rAF while hovering for smooth updates
// - use a small timeout when hiding to avoid flicker when
// briefly leaving and re-entering the plot.
+ //
+ // Re-entering hover while a dismiss timeout is pending should
+ // cancel that timeout so it cannot fire with stale state.
function scheduleRender(updatePinned = false): void {
- if (!controller.renderScheduled) {
- if (!controller.hoverActive) {
- setTimeout(performRender, HOVER_DISMISS_DELAY_MS);
- } else {
- if (rafId.current != null) {
- cancelAnimationFrame(rafId.current);
- }
- rafId.current = requestAnimationFrame(performRender);
- }
- controller.renderScheduled = true;
+ // Always cancel any existing pending callback first so that
+ // a newly scheduled render reflects the latest controller
+ // state (e.g. when quickly re-entering after a brief leave).
+ cancelPendingRender();
+
+ if (controller.hoverActive) {
+ rafId.current = requestAnimationFrame(performRender);
+ } else {
+ dismissTimeoutId.current = setTimeout(
+ performRender,
+ HOVER_DISMISS_DELAY_MS,
+ );
}
+
if (updatePinned) {
controller.pendingPinnedUpdate = true;
}
@@ -300,10 +319,7 @@ export default function TooltipPlugin({
window.removeEventListener('scroll', handleScroll, true);
document.removeEventListener('mousedown', onOutsideInteraction, true);
document.removeEventListener('keydown', onOutsideInteraction, true);
- if (rafId.current != null) {
- cancelAnimationFrame(rafId.current);
- rafId.current = null;
- }
+ cancelPendingRender();
removeReadyHook();
removeInitHook();
removeSetDataHook();
diff --git a/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/tooltipController.ts b/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/tooltipController.ts
index 3c18bb2fb6..dbeaddcb4a 100644
--- a/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/tooltipController.ts
+++ b/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/tooltipController.ts
@@ -1,3 +1,4 @@
+import { isEqual } from 'lodash-es';
import uPlot from 'uplot';
import { TooltipControllerContext, TooltipControllerState } from './types';
@@ -13,7 +14,7 @@ export function createInitialControllerState(): TooltipControllerState {
return {
plot: null,
hoverActive: false,
- anySeriesActive: false,
+ isAnySeriesActive: false,
pinned: false,
style: { transform: '', pointerEvents: 'none' },
horizontalOffset: 0,
@@ -24,7 +25,6 @@ export function createInitialControllerState(): TooltipControllerState {
plotWithinViewport: false,
windowWidth: window.innerWidth - WINDOW_OFFSET,
windowHeight: window.innerHeight - WINDOW_OFFSET,
- renderScheduled: false,
pendingPinnedUpdate: false,
};
}
@@ -79,7 +79,7 @@ export function shouldShowTooltipForSync(
): boolean {
return (
controller.plotWithinViewport &&
- controller.anySeriesActive &&
+ controller.isAnySeriesActive &&
syncTooltipWithDashboard
);
}
@@ -87,7 +87,7 @@ export function shouldShowTooltipForSync(
export function shouldShowTooltipForInteraction(
controller: TooltipControllerState,
): boolean {
- return controller.focusedSeriesIndex != null || controller.anySeriesActive;
+ return controller.focusedSeriesIndex != null || controller.isAnySeriesActive;
}
export function updateHoverState(
@@ -169,18 +169,30 @@ export function createSetLegendHandler(
return;
}
- controller.seriesIndexes = controller.plot.cursor.idxs.slice();
- controller.anySeriesActive = controller.seriesIndexes.some(
- (v, i) => i > 0 && v != null,
+ const newSeriesIndexes = controller.plot.cursor.idxs.slice();
+ const isAnySeriesActive = newSeriesIndexes.some((v, i) => i > 0 && v != null);
+
+ const previousCursorDrivenBySync = controller.cursorDrivenBySync;
+
+ // Skip scheduling if legend data is unchanged
+ const seriesIndexesChanged = !isEqual(
+ controller.seriesIndexes,
+ newSeriesIndexes,
);
+
+ controller.seriesIndexes = newSeriesIndexes;
+ controller.isAnySeriesActive = isAnySeriesActive;
controller.cursorDrivenBySync = u.cursor.event == null;
- // Track transitions into / out of hover so we can avoid
- // unnecessary renders when nothing visible has changed.
const previousHover = controller.hoverActive;
updateHoverState(controller, syncTooltipWithDashboard);
+ const hoverStateChanged = controller.hoverActive !== previousHover;
+
+ const cursorDrivenBySyncChanged =
+ controller.cursorDrivenBySync !== previousCursorDrivenBySync;
- if (controller.hoverActive || controller.hoverActive !== previousHover) {
+ // Only schedule when legend data, hover state, or sync‑driven state has changed
+ if (seriesIndexesChanged || hoverStateChanged || cursorDrivenBySyncChanged) {
ctx.scheduleRender();
}
};
diff --git a/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/types.ts b/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/types.ts
index 99613842e1..0a0ccc83b8 100644
--- a/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/types.ts
+++ b/frontend/src/lib/uPlotV2/plugins/TooltipPlugin/types.ts
@@ -50,7 +50,7 @@ export interface TooltipPluginProps {
export interface TooltipControllerState {
plot: uPlot | null;
hoverActive: boolean;
- anySeriesActive: boolean;
+ isAnySeriesActive: boolean;
pinned: boolean;
style: TooltipViewState['style'];
horizontalOffset: number;
@@ -61,7 +61,6 @@ export interface TooltipControllerState {
plotWithinViewport: boolean;
windowWidth: number;
windowHeight: number;
- renderScheduled: boolean;
pendingPinnedUpdate: boolean;
}