mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user