From a63b8eb034f74994826a5964dc4f83da0ed63f40 Mon Sep 17 00:00:00 2001 From: HugoCasa Date: Fri, 4 Apr 2025 19:55:50 +0200 Subject: [PATCH] fix: app editor svelte 5 fixes (#5570) * fix: properly bind to array elements in Svelte each loops This commit fixes an issue where binding directly to loop variables in Svelte's #each loops doesn't properly update the original array. Instead of binding directly to the loop variable, we now bind to the array elements using index variables. The pattern used is: - Change: {#each arr as el} -> {#each arr as _, index} - Change: bind:value={el} -> bind:value={arr[index]} Modified files: - frontend/src/lib/components/ArrayTypeNarrowing.svelte - frontend/src/lib/components/apps/editor/AppInputs.svelte - frontend/src/lib/components/flows/content/FlowModuleWrapper.svelte * better app settings panel reactivity * fix: app editor table svelte 5 fixes --------- Co-authored-by: Guilhem Co-authored-by: Ruben Fiszel --- .../table/AppAggridExplorerTable.svelte | 3 +- .../display/table/AppAggridTable.svelte | 13 ++------- .../table/AppAggridTableActions.svelte | 29 ++----------------- 3 files changed, 5 insertions(+), 40 deletions(-) diff --git a/frontend/src/lib/components/apps/components/display/table/AppAggridExplorerTable.svelte b/frontend/src/lib/components/apps/components/display/table/AppAggridExplorerTable.svelte index 38a7af9759..e9e5c9599e 100644 --- a/frontend/src/lib/components/apps/components/display/table/AppAggridExplorerTable.svelte +++ b/frontend/src/lib/components/apps/components/display/table/AppAggridExplorerTable.svelte @@ -109,8 +109,7 @@ function refreshActions(actions: TableAction[]) { if (!deepEqual(actions, lastActions)) { - lastActions = [...actions] - + lastActions = structuredClone(actions) updateOptions() } } diff --git a/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte b/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte index a3e7b9b007..cfe10b8991 100644 --- a/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte +++ b/frontend/src/lib/components/apps/components/display/table/AppAggridTable.svelte @@ -202,12 +202,8 @@ function refreshActions(actions: TableAction[]) { if (!deepEqual(actions, lastActions)) { - // structuredClone did not work because it did not copy the array's - // prototype, causing deepEqual to return false although the objects were - // semantically the same - lastActions = [...actions] - // HACK: without setTimeout, the actions mount but aren't visible - setTimeout(updateOptions, 0.5) + lastActions = structuredClone(actions) + updateOptions() } } @@ -459,7 +455,6 @@ } } - let lastComputedColumnDefs: [Record[] | undefined, TableAction[] | undefined] function updateOptions() { try { const columnDefs = @@ -481,10 +476,6 @@ }) } - // Don't update if the columns - if (deepEqual(lastComputedColumnDefs, [columnDefs, actions])) return - lastComputedColumnDefs = [columnDefs, actions] - api?.updateGridOptions({ rowData: value, columnDefs: columnDefs.map((fields) => { diff --git a/frontend/src/lib/components/apps/components/display/table/AppAggridTableActions.svelte b/frontend/src/lib/components/apps/components/display/table/AppAggridTableActions.svelte index 129e534ce2..732569cb69 100644 --- a/frontend/src/lib/components/apps/components/display/table/AppAggridTableActions.svelte +++ b/frontend/src/lib/components/apps/components/display/table/AppAggridTableActions.svelte @@ -1,5 +1,5 @@ {#each actions as action, actionIndex}