Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(spreadsheet): fix double clone on save
Elian Doranf5cc63ebecb0
diff --git a/apps/client/src/widgets/type_widgets/spreadsheet/persistence.spec.ts b/apps/client/src/widgets/type_widgets/spreadsheet/persistence.spec.tsindex 584718b075..41f62cec79 100644--- a/apps/client/src/widgets/type_widgets/spreadsheet/persistence.spec.ts+++ b/apps/client/src/widgets/type_widgets/spreadsheet/persistence.spec.ts@@ -32,7 +32,7 @@ describe("slimWorkbookData", () => {]);});- it("leaves an all-empty resource list as an empty array, tolerates absent resources, and does not mutate the input", () => {+ it("leaves an all-empty resource list as an empty array and tolerates absent resources", () => {expect(slimWorkbookData(makeWorkbook({resources: [{ name: "A", data: "" },@@ -41,10 +41,5 @@ describe("slimWorkbookData", () => {})).resources).toEqual([]);expect(slimWorkbookData(makeWorkbook({})).resources).toBeUndefined();-- const input = makeWorkbook({ id: "keep", resources: [{ name: "A", data: "" }] });- slimWorkbookData(input);- expect(input.id).toBe("keep");- expect(input.resources).toHaveLength(1);});});diff --git a/apps/client/src/widgets/type_widgets/spreadsheet/persistence.tsx b/apps/client/src/widgets/type_widgets/spreadsheet/persistence.tsxindex bf438eaf76..19cee4959f 100644--- a/apps/client/src/widgets/type_widgets/spreadsheet/persistence.tsx+++ b/apps/client/src/widgets/type_widgets/spreadsheet/persistence.tsx@@ -205,10 +205,11 @@ export default function usePersistence(note: FNote, noteContext: NoteContext | n* removed. Univer leaves an absent resource's plugin at its default (empty) state* on load, which is identical to restoring these.*- * Operates on a shallow copy so the live workbook object is left untouched.+ * Mutates the input in place: `workbook.save()` already returns a fresh, deep-cloned+ * snapshot that the caller owns, so there is nothing live to protect.*/export function slimWorkbookData(workbookData: IWorkbookData): Partial<IWorkbookData> {- const slimmed: Partial<IWorkbookData> = { ...workbookData };+ const slimmed = workbookData as Partial<IWorkbookData>;delete slimmed.id;if (slimmed.resources) {