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>
This commit is contained in:
OrcaWin
2026-10-28 17:26:43 -07:00
committed by GitHub
co-authored by OrcaWin
parent 918cc3a8cc
commit 2f3cdbab78
@@ -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)