From 2f3cdbab782217196731d788320f7f0f2c65df41 Mon Sep 17 00:00:00 2001 From: OrcaWin Date: Wed, 28 Oct 2026 17:26:43 -0700 Subject: [PATCH] perf(editor): memoize image identity key across zoom renders (#35001) Zoom and resize re-renders reuse the same key string instead of rebuilding and comparing it, which matters for base64-backed images (diff, conflict review, fallbacks) where the key embeds the whole payload. Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com> --- src/renderer/src/components/editor/ImageViewer.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/components/editor/ImageViewer.tsx b/src/renderer/src/components/editor/ImageViewer.tsx index 5e97c85fe7a..fafa68b1ab1 100644 --- a/src/renderer/src/components/editor/ImageViewer.tsx +++ b/src/renderer/src/components/editor/ImageViewer.tsx @@ -65,7 +65,12 @@ export default function ImageViewer({ const filename = useMemo(() => filePath.split(/[/\\]/).pop() || filePath, [filePath]) const cleanedContent = useMemo(() => content.replace(/\s/g, ''), [content]) // A remint changes only the URL's revision; keep zoom unless the grant or the file's size changed. - const imageStateKey = `${filePath}\n${mimeType}\n${src ? `${src.split('?')[0]}\n${byteSize ?? ''}` : cleanedContent}` + const srcIdentity = src ? src.split('?')[0] : undefined + const imageStateKey = useMemo( + () => + `${filePath}\n${mimeType}\n${srcIdentity !== undefined ? `${srcIdentity}\n${byteSize ?? ''}` : cleanedContent}`, + [filePath, mimeType, srcIdentity, byteSize, cleanedContent] + ) const [lastImageStateKey, setLastImageStateKey] = useState(imageStateKey) if (lastImageStateKey !== imageStateKey) { setLastImageStateKey(imageStateKey)