From ed042d205692b3327937c0f1fc4de3ac3a6559f5 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 5 Dec 2021 18:39:11 +0100 Subject: [PATCH] core-components: memo LogViewer LogLines Signed-off-by: Patrik Oldsberg --- .../src/components/LogViewer/LogLine.tsx | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) 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}; }