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: address final code review issues - structuredClone guard, variable rename, clarifying comment

copilot-swe-agent[bot]fdf2e36c504e
diff --git a/apps/image/src/stores/history-store.ts b/apps/image/src/stores/history-store.ts
index 8d60db45..f26561c1 100644
--- a/apps/image/src/stores/history-store.ts
+++ b/apps/image/src/stores/history-store.ts
@@ -231,10 +231,10 @@ export const useHistoryStore = create<HistoryState & HistoryActions>()(
for (let i = 0; i <= index; i++) {
project = undoStack[i].command.apply(project);
}
- // Commands past the target index become the redo stack, with the
- // next-to-apply command at the end (to be popped first on redo).
- const futureCommands = undoStack.slice(index + 1).reverse();
- set({ undoStack: undoStack.slice(0, index + 1), redoStack: futureCommands });
+ // Commands past the target index become the redo stack, reversed so that
+ // the next command to re-apply (index+1) is at the end (popped first on redo).
+ const redoCommands = undoStack.slice(index + 1).reverse();
+ set({ undoStack: undoStack.slice(0, index + 1), redoStack: redoCommands });
return project;
} catch {
return null;
diff --git a/apps/image/src/stores/project-store.ts b/apps/image/src/stores/project-store.ts
index 9efd9079..447606ba 100644
--- a/apps/image/src/stores/project-store.ts
+++ b/apps/image/src/stores/project-store.ts
@@ -822,6 +822,7 @@ export const useProjectStore = create<ProjectState & ProjectActions>()(
if (!copiedStyle || !selectedLayerIds.length || !currentProject) return;
for (const layerId of selectedLayerIds) {
+ // Read from currentProject (updated after each command) to get fresh prevValues.
const layer = currentProject.layers[layerId];
if (!layer) continue;
const styleUpdates: Partial<Layer> = {
diff --git a/packages/image-core/src/commands.ts b/packages/image-core/src/commands.ts
index 8770f84e..26f836d3 100644
--- a/packages/image-core/src/commands.ts
+++ b/packages/image-core/src/commands.ts
@@ -582,9 +582,10 @@ export class GroupLayersCommand implements Command {
const { childIds } = this.groupLayer;
childIds.forEach((childId) => {
if (next.layers[childId]) {
+ const childBefore = this.childLayersBefore[childId];
next.layers[childId] = {
...next.layers[childId],
- ...(structuredClone(this.childLayersBefore[childId]) ?? {}),
+ ...(childBefore ? structuredClone(childBefore) : {}),
parentId: this.groupLayer.id,
};
}