Create professional demos and 3D mockups in seconds, directly in your browser
feat: enhance CanvasElementsLayer with memoization and improve VideoCanvas performance by stabilizing visible elements
CristianOlivera15b2c7ddc2af7
diff --git a/.gitignore b/.gitignoreindex 08deee2..9effdfd 100644--- a/.gitignore+++ b/.gitignore@@ -47,4 +47,5 @@ BACKEND_SPEC.mdBACKEND_TESTING.md/openvid-back/openvid-autozoom-plan-integracion-openvid-autozoom.md\ No newline at end of file+plan-integracion-openvid-autozoom.md+/scripts\ No newline at end of filediff --git a/app/components/ui/editor/CanvasElementsLayer.tsx b/app/components/ui/editor/CanvasElementsLayer.tsxindex f4c3505..b927a3b 100644--- a/app/components/ui/editor/CanvasElementsLayer.tsx+++ b/app/components/ui/editor/CanvasElementsLayer.tsx@@ -9,7 +9,7 @@ import {CORNER_RESIZE_CURSOR,} from "@/lib";import { CanvasElement, SvgElement, ImageElement, TextElement } from "@/types/canvas-elements.types";-import { useRef, useState, useEffect, useCallback, useMemo } from "react";+import { useRef, useState, useEffect, useCallback, useMemo, memo } from "react";export interface ElementResizeStart {id: string;@@ -96,7 +96,7 @@ function InlineTextEditor({);}-export function CanvasElementsLayer({+function CanvasElementsLayerImpl({canvasContainerRef,canvasElements,selectedElementId,@@ -538,4 +538,5 @@ export function CanvasElementsLayer({})}</div>);-}\ No newline at end of file+}+export const CanvasElementsLayer = memo(CanvasElementsLayerImpl);diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsxindex 5cd9d0a..b932671 100644--- a/app/components/ui/editor/VideoCanvas.tsx+++ b/app/components/ui/editor/VideoCanvas.tsx@@ -261,10 +261,21 @@ function VideoCanvasInner({return getThumbnailForTime(scrubTime);}, [isScrubbing, scrubTime, getThumbnailForTime]);+const visibleCanvasElements = useMemo(() => {if (mediaType !== "video") return canvasElements;return filterVisibleElements(canvasElements, currentTime, videoDuration);}, [mediaType, canvasElements, currentTime, videoDuration]);+ const visibleElementsKey = visibleCanvasElements.map(e => e.id).join(',');+ const [stableVisibleElements, setStableVisibleElements] = useState(visibleCanvasElements);+ const [stableVisibleKey, setStableVisibleKey] = useState(visibleElementsKey);+ const [stableElementsSrc, setStableElementsSrc] = useState(canvasElements);++ if (canvasElements !== stableElementsSrc || visibleElementsKey !== stableVisibleKey) {+ setStableElementsSrc(canvasElements);+ setStableVisibleKey(visibleElementsKey);+ setStableVisibleElements(visibleCanvasElements);+ }// Find active zoom fragment based on current timeconst activeZoomFragment = useMemo<ZoomFragment | null>(() => {@@ -2118,7 +2129,7 @@ function VideoCanvasInner({{/* Capa 2A: Canvas elements BEHIND video — sin rotación 3D */}<CanvasElementsLayercanvasContainerRef={canvasContainerRef}- canvasElements={visibleCanvasElements}+ canvasElements={stableVisibleElements}selectedElementId={selectedElementId}selectedElementIds={canvasSelectedIds}hoveredElementId={hoveredElementId}@@ -2385,7 +2396,7 @@ function VideoCanvasInner({{/* Capa 3: Canvas elements ABOVE video (zIndex >= VIDEO_Z_INDEX) */}<CanvasElementsLayercanvasContainerRef={undefined}- canvasElements={visibleCanvasElements}+ canvasElements={stableVisibleElements}selectedElementId={selectedElementId}selectedElementIds={canvasSelectedIds}hoveredElementId={hoveredElementId}@@ -2411,7 +2422,7 @@ function VideoCanvasInner({{/* Capa HIT: invisible, todos los elementos, para recibir eventos */}<CanvasElementsLayercanvasContainerRef={undefined}- canvasElements={visibleCanvasElements}+ canvasElements={stableVisibleElements}selectedElementId={selectedElementId}selectedElementIds={canvasSelectedIds}hoveredElementId={hoveredElementId}