Skip to content

Commit be8e5b5

Browse files
MattPuamatt-metivier
authored andcommitted
perf(dashboard): Memoize part of text card tiles for perf improvements with edit mode (#52090)
1 parent d37eaff commit be8e5b5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

frontend/src/lib/components/Cards/TextCard/TextCard.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import './TextCard.scss'
22

33
import { EditorContent } from '@tiptap/react'
44
import clsx from 'clsx'
5-
import React, { useEffect } from 'react'
5+
import React, { memo, useEffect, useMemo } from 'react'
66

77
import 'lib/components/MarkdownEditor/RichMarkdownEditor.scss'
88
import { Resizeable } from 'lib/components/Cards/CardMeta'
@@ -36,10 +36,12 @@ interface TextCardBodyProps extends Pick<React.HTMLAttributes<HTMLDivElement>, '
3636
closeDetails?: () => void
3737
}
3838

39-
export function TextContent({ text, closeDetails, className }: TextCardBodyProps): JSX.Element {
39+
function TextContentImpl({ text, closeDetails, className }: TextCardBodyProps): JSX.Element {
40+
const initialDoc = useMemo(() => markdownToTextCardDoc(text), [text])
41+
4042
const editor = useRichContentEditor({
4143
extensions: TEXT_CARD_MARKDOWN_READONLY_EXTENSIONS,
42-
initialContent: markdownToTextCardDoc(text),
44+
initialContent: initialDoc,
4345
disabled: true,
4446
})
4547

@@ -48,8 +50,8 @@ export function TextContent({ text, closeDetails, className }: TextCardBodyProps
4850
return
4951
}
5052

51-
editor.commands.setContent(markdownToTextCardDoc(text), { emitUpdate: false })
52-
}, [editor, text])
53+
editor.commands.setContent(initialDoc, { emitUpdate: false })
54+
}, [editor, initialDoc])
5355

5456
return (
5557
<div className={clsx('w-full', className)} onClick={() => closeDetails?.()}>
@@ -64,6 +66,9 @@ export function TextContent({ text, closeDetails, className }: TextCardBodyProps
6466
)
6567
}
6668

69+
export const TextContent = memo(TextContentImpl)
70+
TextContent.displayName = 'TextContent'
71+
6772
function TextCardInternal(
6873
{
6974
textTile,

0 commit comments

Comments
 (0)