diff --git a/packages/core-components/src/components/LogViewer/LogLine.tsx b/packages/core-components/src/components/LogViewer/LogLine.tsx
index f1296982b0..c14df4a45a 100644
--- a/packages/core-components/src/components/LogViewer/LogLine.tsx
+++ b/packages/core-components/src/components/LogViewer/LogLine.tsx
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import React from 'react';
+import React, { useMemo } from 'react';
import { AnsiChunk, AnsiLine, ChunkModifiers } from './AnsiProcessor';
import startCase from 'lodash/startCase';
import clsx from 'clsx';
@@ -150,22 +150,29 @@ export function LogLine({
searchText,
highlightResultIndex,
}: LogLineProps) {
- const chunks = calculateHighlightedChunks(line, searchText);
+ const chunks = useMemo(
+ () => calculateHighlightedChunks(line, searchText),
+ [line, searchText],
+ );
- const elements = chunks.map(({ text, modifiers, highlight }, index) => (
-
- {text}
-
- ));
+ const elements = useMemo(
+ () =>
+ chunks.map(({ text, modifiers, highlight }, index) => (
+
+ {text}
+
+ )),
+ [chunks, highlightResultIndex, classes],
+ );
return <>{elements}>;
}