Skip to content

OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.

TypeScript

fix: SVG/emoji clips not appearing and emoji resize broken

Augustus Otu748381b99c43
diff --git a/apps/web/src/components/editor/Preview.tsx b/apps/web/src/components/editor/Preview.tsx
index 9e50c29b..5a6de8d1 100644
--- a/apps/web/src/components/editor/Preview.tsx
+++ b/apps/web/src/components/editor/Preview.tsx
@@ -58,6 +58,7 @@ import {
drawFrameWithTransform,
applyEffectsToFrame,
getTransitionAtTime,
+ setImageLoadCallback,
renderTransitionFrame,
getAnimatedTransform,
applyEmphasisAnimation,
@@ -1547,6 +1548,30 @@ export const Preview: React.FC = () => {
],
);
+ const renderFrameDirectlyRef = useRef(renderFrameDirectly);
+ useEffect(() => {
+ renderFrameDirectlyRef.current = renderFrameDirectly;
+ }, [renderFrameDirectly]);
+
+ const isPlayingRef = useRef(isPlaying);
+ useEffect(() => {
+ isPlayingRef.current = isPlaying;
+ }, [isPlaying]);
+
+ const playheadPositionRef = useRef(playheadPosition);
+ useEffect(() => {
+ playheadPositionRef.current = playheadPosition;
+ }, [playheadPosition]);
+
+ useEffect(() => {
+ setImageLoadCallback(() => {
+ if (!isPlayingRef.current) {
+ renderFrameDirectlyRef.current(playheadPositionRef.current);
+ }
+ });
+ return () => setImageLoadCallback(null);
+ }, []);
+
const renderFallbackFrame = useCallback(
(time: number) => {
const canvas = canvasRef.current;
diff --git a/apps/web/src/components/editor/preview/canvas-renderers.ts b/apps/web/src/components/editor/preview/canvas-renderers.ts
index 31ae4d93..c71b9e92 100644
--- a/apps/web/src/components/editor/preview/canvas-renderers.ts
+++ b/apps/web/src/components/editor/preview/canvas-renderers.ts
@@ -785,6 +785,12 @@ export const getActiveShapeClips = (
const svgImageCache = new Map<string, HTMLImageElement>();
const stickerImageCache = new Map<string, HTMLImageElement>();
+let imageLoadCallback: (() => void) | null = null;
+
+export const setImageLoadCallback = (callback: (() => void) | null): void => {
+ imageLoadCallback = callback;
+};
+
const renderStickerClip = (
ctx: CanvasRenderingContext2D,
stickerClip: StickerClip,
@@ -812,6 +818,7 @@ const renderStickerClip = (
let img = stickerImageCache.get(imageUrl);
if (!img) {
img = new Image();
+ img.onload = () => imageLoadCallback?.();
img.src = imageUrl;
stickerImageCache.set(imageUrl, img);
}
@@ -1176,6 +1183,7 @@ const renderSVGClip = (
if (!img) {
img = new Image();
const blob = new Blob([svgContent], { type: "image/svg+xml" });
+ img.onload = () => imageLoadCallback?.();
img.src = URL.createObjectURL(blob);
svgImageCache.set(cacheKey, img);
// Limit cache size to prevent unbounded memory growth, remove oldest on overflow
diff --git a/apps/web/src/stores/project-store.ts b/apps/web/src/stores/project-store.ts
index d4290917..a3fec2b9 100644
--- a/apps/web/src/stores/project-store.ts
+++ b/apps/web/src/stores/project-store.ts
@@ -278,7 +278,7 @@ export interface ProjectState {
updateShapeTransform: (
clipId: string,
transform: Partial<Transform>,
- ) => ShapeClip | SVGClip | null;
+ ) => ShapeClip | SVGClip | StickerClip | null;
importSVG: (
svgContent: string,
trackId: string,
@@ -3207,6 +3207,21 @@ export const useProjectStore = create<ProjectState>()(
return updatedClip || null;
}
+ const stickerClip = graphicsEngine.getStickerClip(clipId);
+ if (stickerClip) {
+ const updatedClip = graphicsEngine.updateStickerClip(clipId, {
+ transform,
+ });
+ const { project } = get();
+ set({
+ project: {
+ ...project,
+ modifiedAt: Date.now(),
+ },
+ });
+ return updatedClip || null;
+ }
+
console.error(`Graphic clip ${clipId} not found`);
return null;
},
diff --git a/apps/web/src/stores/project/types.ts b/apps/web/src/stores/project/types.ts
index f1c32cd3..0047826a 100644
--- a/apps/web/src/stores/project/types.ts
+++ b/apps/web/src/stores/project/types.ts
@@ -182,7 +182,7 @@ export interface ProjectState {
updateShapeTransform: (
clipId: string,
transform: Partial<Transform>,
- ) => ShapeClip | null;
+ ) => ShapeClip | SVGClip | StickerClip | null;
importSVG: (
svgContent: string,
trackId: string,