From c15d9f7645d06b60445ce1b9bc2a819c62a1d914 Mon Sep 17 00:00:00 2001 From: Amruth Pillai Date: Fri, 10 May 2024 11:27:13 +0200 Subject: [PATCH] revert `structuredClone` as it is not supported on proxy objects --- .eslintrc.json | 3 ++- .../pages/builder/sidebars/left/sections/custom/section.tsx | 2 +- .../src/pages/builder/sidebars/right/sections/layout.tsx | 6 +++--- apps/client/src/stores/resume.ts | 6 +++--- libs/parser/src/json-resume/index.ts | 2 +- libs/parser/src/linkedin/index.ts | 2 +- libs/parser/src/reactive-resume-v3/index.ts | 2 +- libs/utils/src/namespaces/array.ts | 2 +- libs/utils/src/namespaces/tests/array.test.ts | 2 +- package.json | 2 +- 10 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9bec07e8..60b4ce07 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -76,7 +76,8 @@ // unicorn "unicorn/no-null": "off", "unicorn/prevent-abbreviations": "off", - "unicorn/prefer-string-replace-all": "off" + "unicorn/prefer-string-replace-all": "off", + "unicorn/prefer-structured-clone": "off" } }, { diff --git a/apps/client/src/pages/builder/sidebars/left/sections/custom/section.tsx b/apps/client/src/pages/builder/sidebars/left/sections/custom/section.tsx index dfe556f4..3998f162 100644 --- a/apps/client/src/pages/builder/sidebars/left/sections/custom/section.tsx +++ b/apps/client/src/pages/builder/sidebars/left/sections/custom/section.tsx @@ -91,7 +91,7 @@ export const CustomFieldsSection = ({ className }: Props) => { const onChangeCustomField = (field: ICustomField) => { const index = customFields.findIndex((item) => item.id === field.id); - const newCustomFields = structuredClone(customFields); + const newCustomFields = JSON.parse(JSON.stringify(customFields)); newCustomFields[index] = field; setValue("basics.customFields", newCustomFields); diff --git a/apps/client/src/pages/builder/sidebars/right/sections/layout.tsx b/apps/client/src/pages/builder/sidebars/right/sections/layout.tsx index 443077c4..b0e07bd8 100644 --- a/apps/client/src/pages/builder/sidebars/right/sections/layout.tsx +++ b/apps/client/src/pages/builder/sidebars/right/sections/layout.tsx @@ -163,7 +163,7 @@ export const LayoutSection = () => { }; const onAddPage = () => { - const layoutCopy = structuredClone(layout); + const layoutCopy = JSON.parse(JSON.stringify(layout)); layoutCopy.push([[], []]); @@ -171,7 +171,7 @@ export const LayoutSection = () => { }; const onRemovePage = (page: number) => { - const layoutCopy = structuredClone(layout); + const layoutCopy = JSON.parse(JSON.stringify(layout)); layoutCopy[0][0].push(...layoutCopy[page][0]); // Main layoutCopy[0][1].push(...layoutCopy[page][1]); // Sidebar @@ -182,7 +182,7 @@ export const LayoutSection = () => { }; const onResetLayout = () => { - const layoutCopy = structuredClone(defaultMetadata.layout); + const layoutCopy = JSON.parse(JSON.stringify(defaultMetadata.layout)); // Loop through all pages and columns, and get any sections that start with "custom." // These should be appended to the first page of the new layout. diff --git a/apps/client/src/stores/resume.ts b/apps/client/src/stores/resume.ts index 7bdcb778..1dfc1a91 100644 --- a/apps/client/src/stores/resume.ts +++ b/apps/client/src/stores/resume.ts @@ -35,7 +35,7 @@ export const useResumeStore = create()( state.resume.data = _set(state.resume.data, path, value); } - void debouncedUpdateResume(structuredClone(state.resume)); + void debouncedUpdateResume(JSON.parse(JSON.stringify(state.resume))); }); }, addSection: () => { @@ -51,7 +51,7 @@ export const useResumeStore = create()( state.resume.data.metadata.layout[lastPageIndex][0].push(`custom.${section.id}`); state.resume.data = _set(state.resume.data, `sections.custom.${section.id}`, section); - void debouncedUpdateResume(structuredClone(state.resume)); + void debouncedUpdateResume(JSON.parse(JSON.stringify(state.resume))); }); }, removeSection: (sectionId: SectionKey) => { @@ -63,7 +63,7 @@ export const useResumeStore = create()( // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete state.resume.data.sections.custom[id]; - void debouncedUpdateResume(structuredClone(state.resume)); + void debouncedUpdateResume(JSON.parse(JSON.stringify(state.resume))); }); } }, diff --git a/libs/parser/src/json-resume/index.ts b/libs/parser/src/json-resume/index.ts index 1323b0c4..9b8abea7 100644 --- a/libs/parser/src/json-resume/index.ts +++ b/libs/parser/src/json-resume/index.ts @@ -57,7 +57,7 @@ export class JsonResumeParser implements Parser { } convert(data: JsonResume) { - const result = structuredClone(defaultResumeData); + const result = JSON.parse(JSON.stringify(defaultResumeData)); // Basics result.basics.name = data.basics?.name ?? ""; diff --git a/libs/parser/src/linkedin/index.ts b/libs/parser/src/linkedin/index.ts index 844fc690..2142f1ae 100644 --- a/libs/parser/src/linkedin/index.ts +++ b/libs/parser/src/linkedin/index.ts @@ -57,7 +57,7 @@ export class LinkedInParser implements Parser { } convert(data: LinkedIn) { - const result = structuredClone(defaultResumeData); + const result = JSON.parse(JSON.stringify(defaultResumeData)); // Profile if (data.Profile && data.Profile.length > 0) { diff --git a/libs/parser/src/reactive-resume-v3/index.ts b/libs/parser/src/reactive-resume-v3/index.ts index f49c2957..58c823d6 100644 --- a/libs/parser/src/reactive-resume-v3/index.ts +++ b/libs/parser/src/reactive-resume-v3/index.ts @@ -59,7 +59,7 @@ export class ReactiveResumeV3Parser implements Parser { } convert(data: ReactiveResumeV3) { - const result = structuredClone(defaultResumeData); + const result = JSON.parse(JSON.stringify(defaultResumeData)); // Basics result.basics.name = data.basics.name ?? ""; diff --git a/libs/utils/src/namespaces/array.ts b/libs/utils/src/namespaces/array.ts index e8874b1f..62816476 100644 --- a/libs/utils/src/namespaces/array.ts +++ b/libs/utils/src/namespaces/array.ts @@ -34,7 +34,7 @@ export const moveItemInLayout = ( ): string[][][] => { try { // Create a deep copy of the layout to avoid mutating the original array - const newLayout = structuredClone(layout); + const newLayout = JSON.parse(JSON.stringify(layout)); // Get the item from the current location const item = newLayout[current.page][current.column][current.section]; diff --git a/libs/utils/src/namespaces/tests/array.test.ts b/libs/utils/src/namespaces/tests/array.test.ts index 59fbc107..4d724647 100644 --- a/libs/utils/src/namespaces/tests/array.test.ts +++ b/libs/utils/src/namespaces/tests/array.test.ts @@ -84,7 +84,7 @@ describe("moveItemInLayout", () => { [["item1"], ["item2"]], [["item3"], ["item4"]], ]; - const layoutCopy = structuredClone(layout); + const layoutCopy = JSON.parse(JSON.stringify(layout)); const current = { page: 0, column: 1, section: 0 }; const target = { page: 1, column: 0, section: 1 }; diff --git a/package.json b/package.json index 138991cd..77f19791 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@reactive-resume/source", "description": "A free and open-source resume builder that simplifies the process of creating, updating, and sharing your resume.", - "version": "4.1.2", + "version": "4.1.3", "license": "MIT", "private": true, "author": {