From d9b4f1fc6af7b3ebd8613d5a8ec926cbcef383f0 Mon Sep 17 00:00:00 2001 From: Mark Tolmacs Date: Wed, 24 Jun 2026 15:52:47 +0000 Subject: [PATCH] fix: Elements cache Signed-off-by: Mark Tolmacs --- packages/excalidraw/scroll.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/excalidraw/scroll.ts b/packages/excalidraw/scroll.ts index e6410e2d6d..b7e8a09f55 100644 --- a/packages/excalidraw/scroll.ts +++ b/packages/excalidraw/scroll.ts @@ -1,4 +1,5 @@ import { easeOut } from "@excalidraw/common"; +import { clamp } from "@excalidraw/math"; import type { ExcalidrawElement } from "@excalidraw/element/types"; @@ -102,21 +103,22 @@ const animateToViewport = ( from: Pick, target: Viewport, duration: number, - onFrame: (state: Pick) => void, + onFrame: ( + state: Pick< + AppState, + "scrollX" | "scrollY" | "zoom" | "shouldCacheIgnoreZoom" + >, + ) => void, ) => { AnimationController.start<{ elapsed: number }>( SCROLL_TO_CONTENT_ANIMATION_KEY, ({ deltaTime, state }) => { const elapsed = (state?.elapsed ?? 0) + deltaTime; const progress = Math.min(elapsed / duration, 1); - - if (progress >= 1) { - return null; - } - - const factor = easeOut(progress); + const factor = easeOut(clamp(progress, 0, 1)); onFrame({ + shouldCacheIgnoreZoom: progress < 1, // ignore zoom caching while animating scrollX: from.scrollX + (target.scrollX - from.scrollX) * factor, scrollY: from.scrollY + (target.scrollY - from.scrollY) * factor, // zoom interpolates geometrically so the transition feels natural