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.

perf(logs): reduce amount of re-renders (#9839)

Vinicius Lourençoa0b722887d4f
diff --git a/frontend/src/components/Logs/ListLogView/index.tsx b/frontend/src/components/Logs/ListLogView/index.tsx
index f30adf4d91..a5376a302f 100644
--- a/frontend/src/components/Logs/ListLogView/index.tsx
+++ b/frontend/src/components/Logs/ListLogView/index.tsx
@@ -14,7 +14,7 @@ import { useIsDarkMode } from 'hooks/useDarkMode';
// utils
import { FlatLogData } from 'lib/logs/flatLogData';
import { useTimezone } from 'providers/Timezone';
-import { useCallback, useMemo, useState } from 'react';
+import { memo, useCallback, useMemo } from 'react';
// interfaces
import { IField } from 'types/api/logs/fields';
import { ILog } from 'types/api/logs/log';
@@ -121,10 +121,11 @@ function ListLogView({
}: ListLogViewProps): JSX.Element {
const flattenLogData = useMemo(() => FlatLogData(logData), [logData]);
- const [hasActionButtons, setHasActionButtons] = useState<boolean>(false);
const { isHighlighted, isLogsExplorerPage, onLogCopy } = useCopyLogLink(
logData.id,
);
+ const isReadOnlyLog = !isLogsExplorerPage;
+
const {
activeLog: activeContextLog,
onAddToQuery: handleAddToQuery,
@@ -180,14 +181,6 @@ function ListLogView({
const logType = getLogIndicatorType(logData);
- const handleMouseEnter = (): void => {
- setHasActionButtons(true);
- };
-
- const handleMouseLeave = (): void => {
- setHasActionButtons(false);
- };
-
return (
<>
<Container
@@ -198,8 +191,6 @@ function ListLogView({
}
$isDarkMode={isDarkMode}
$logType={logType}
- onMouseEnter={handleMouseEnter}
- onMouseLeave={handleMouseLeave}
onClick={handleDetailedView}
fontSize={fontSize}
>
@@ -251,7 +242,7 @@ function ListLogView({
</div>
</div>
- {hasActionButtons && isLogsExplorerPage && (
+ {!isReadOnlyLog && (
<LogLinesActionButtons
handleShowContext={handleShowContext}
onLogCopy={onLogCopy}
@@ -279,4 +270,4 @@ LogGeneralField.defaultProps = {
linesPerRow: 1,
};
-export default ListLogView;
+export default memo(ListLogView);
diff --git a/frontend/src/components/Logs/ListLogView/styles.ts b/frontend/src/components/Logs/ListLogView/styles.ts
index 0f094b0615..2763817ee2 100644
--- a/frontend/src/components/Logs/ListLogView/styles.ts
+++ b/frontend/src/components/Logs/ListLogView/styles.ts
@@ -30,6 +30,11 @@ export const Container = styled(Card)<{
? `margin-bottom:0.3rem;`
: ``}
cursor: pointer;
+
+ &:not(:hover) .log-line-action-buttons {
+ display: none;
+ }
+
.ant-card-body {
padding: 0.3rem 0.6rem;
diff --git a/frontend/src/components/Logs/LogLinesActionButtons/LogLinesActionButtons.tsx b/frontend/src/components/Logs/LogLinesActionButtons/LogLinesActionButtons.tsx
index af6da290fb..0ecffb253e 100644
--- a/frontend/src/components/Logs/LogLinesActionButtons/LogLinesActionButtons.tsx
+++ b/frontend/src/components/Logs/LogLinesActionButtons/LogLinesActionButtons.tsx
@@ -3,14 +3,15 @@ import './LogLinesActionButtons.styles.scss';
import { LinkOutlined } from '@ant-design/icons';
import { Button, Tooltip } from 'antd';
import { TextSelect } from 'lucide-react';
-import { MouseEventHandler } from 'react';
+import { memo, MouseEventHandler } from 'react';
export interface LogLinesActionButtonsProps {
handleShowContext: MouseEventHandler<HTMLElement>;
onLogCopy: MouseEventHandler<HTMLElement>;
customClassName?: string;
}
-export default function LogLinesActionButtons({
+
+function LogLinesActionButtons({
handleShowContext,
onLogCopy,
customClassName = '',
@@ -40,3 +41,5 @@ export default function LogLinesActionButtons({
LogLinesActionButtons.defaultProps = {
customClassName: '',
};
+
+export default memo(LogLinesActionButtons);
diff --git a/frontend/src/components/Logs/RawLogView/index.tsx b/frontend/src/components/Logs/RawLogView/index.tsx
index c9b73497c5..68b8a3b16f 100644
--- a/frontend/src/components/Logs/RawLogView/index.tsx
+++ b/frontend/src/components/Logs/RawLogView/index.tsx
@@ -4,7 +4,6 @@ import LogDetail from 'components/LogDetail';
import { VIEW_TYPES, VIEWS } from 'components/LogDetail/constants';
import { DATE_TIME_FORMATS } from 'constants/dateTimeFormats';
import { getSanitizedLogBody } from 'container/LogDetailedView/utils';
-import LogsExplorerContext from 'container/LogsExplorerContext';
import { useActiveLog } from 'hooks/logs/useActiveLog';
import { useCopyLogLink } from 'hooks/logs/useCopyLogLink';
// hooks
@@ -14,6 +13,7 @@ import { isEmpty, isNumber, isUndefined } from 'lodash-es';
import { useTimezone } from 'providers/Timezone';
import {
KeyboardEvent,
+ memo,
MouseEvent,
MouseEventHandler,
useCallback,
@@ -47,10 +47,6 @@ function RawLogView({
} = useCopyLogLink(data.id);
const flattenLogData = useMemo(() => FlatLogData(data), [data]);
- const {
- activeLog: activeContextLog,
- onClearActiveLog: handleClearActiveContextLog,
- } = useActiveLog();
const {
activeLog,
onSetActiveLog,
@@ -59,7 +55,6 @@ function RawLogView({
onGroupByAttribute,
} = useActiveLog();
- const [hasActionButtons, setHasActionButtons] = useState<boolean>(false);
const [selectedTab, setSelectedTab] = useState<VIEWS | undefined>();
const isDarkMode = useIsDarkMode();
@@ -132,7 +127,7 @@ function RawLogView({
const handleClickExpand = useCallback(
(event: MouseEvent) => {
- if (activeContextLog || isReadOnly) return;
+ if (isReadOnly) return;
// Use custom click handler if provided, otherwise use default behavior
if (onLogClick) {
@@ -142,7 +137,7 @@ function RawLogView({
setSelectedTab(VIEW_TYPES.OVERVIEW);
}
},
- [activeContextLog, isReadOnly, data, onSetActiveLog, onLogClick],
+ [isReadOnly, data, onSetActiveLog, onLogClick],
);
const handleCloseLogDetail: DrawerProps['onClose'] = useCallback(
@@ -158,18 +153,6 @@ function RawLogView({
[onClearActiveLog],
);
- const handleMouseEnter = useCallback(() => {
- if (isReadOnlyLog) return;
-
- setHasActionButtons(true);
- }, [isReadOnlyLog]);
-
- const handleMouseLeave = useCallback(() => {
- if (isReadOnlyLog) return;
-
- setHasActionButtons(false);
- }, [isReadOnlyLog]);
-
const handleShowContext: MouseEventHandler<HTMLElement> = useCallback(
(event) => {
event.preventDefault();
@@ -196,13 +179,9 @@ function RawLogView({
$isDarkMode={isDarkMode}
$isReadOnly={isReadOnly}
$isHightlightedLog={isUrlHighlighted}
- $isActiveLog={
- activeLog?.id === data.id || activeContextLog?.id === data.id || isActiveLog
- }
+ $isActiveLog={activeLog?.id === data.id || isActiveLog}
$isCustomHighlighted={isHighlighted}
$logType={logType}
- onMouseEnter={handleMouseEnter}
- onMouseLeave={handleMouseLeave}
fontSize={fontSize}
>
<LogStateIndicator
@@ -231,19 +210,13 @@ function RawLogView({
dangerouslySetInnerHTML={html}
/>
- {hasActionButtons && (
+ {!isReadOnlyLog && (
<LogLinesActionButtons
handleShowContext={handleShowContext}
onLogCopy={onLogCopy}
/>
)}
- {activeContextLog && (
- <LogsExplorerContext
- log={activeContextLog}
- onClose={handleClearActiveContextLog}
- />
- )}
{selectedTab && (
<LogDetail
selectedTab={selectedTab}
@@ -265,4 +238,4 @@ RawLogView.defaultProps = {
isHighlighted: false,
};
-export default RawLogView;
+export default memo(RawLogView);
diff --git a/frontend/src/components/Logs/RawLogView/styles.ts b/frontend/src/components/Logs/RawLogView/styles.ts
index e004a6cc26..2017933563 100644
--- a/frontend/src/components/Logs/RawLogView/styles.ts
+++ b/frontend/src/components/Logs/RawLogView/styles.ts
@@ -30,6 +30,10 @@ export const RawLogViewContainer = styled(Row)<{
transition: background-color 0.2s ease-in;
+ &:not(:hover) .log-line-action-buttons {
+ display: none;
+ }
+
.log-state-indicator {
margin: 4px 0;