Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

perf(editor): defer slider bounds updates and close undo groups

Richie McIlroy784066202b29
diff --git a/apps/desktop/src/routes/editor/ui.tsx b/apps/desktop/src/routes/editor/ui.tsx
index 3dd6577f8..ab46db4b6 100644
--- a/apps/desktop/src/routes/editor/ui.tsx
+++ b/apps/desktop/src/routes/editor/ui.tsx
@@ -15,6 +15,7 @@ import {
createSignal,
type JSX,
mergeProps,
+ onCleanup,
type ParentProps,
Show,
splitProps,
@@ -163,10 +164,25 @@ export function Slider(
// Pause history when slider is being dragged
let resumeHistory: (() => void) | null = null;
+ onCleanup(() => resumeHistory?.());
const [thumbRef, setThumbRef] = createSignal<HTMLDivElement>();
- const thumbBounds = createElementBounds(thumbRef);
+ let boundsFrame: number | undefined;
+ const deferBoundsUpdate = (update: () => void) => () => {
+ if (boundsFrame !== undefined) return;
+ boundsFrame = requestAnimationFrame(() => {
+ boundsFrame = undefined;
+ update();
+ });
+ };
+ onCleanup(() => {
+ if (boundsFrame !== undefined) cancelAnimationFrame(boundsFrame);
+ });
+ const thumbBounds = createElementBounds(thumbRef, {
+ trackResize: deferBoundsUpdate,
+ trackMutation: deferBoundsUpdate,
+ });
const [dragging, setDragging] = createSignal(false);