From fc128f4584699c9842bf3938a881ef923931fc50 Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Tue, 15 Jul 2025 21:49:22 +0500
Subject: [PATCH] fix: Form child element not updating

---
 .../src/comps/comps/formComp/formComp.tsx       | 17 +++++++++--------
 .../lowcoder/src/redux/sagas/orgSagas.ts        | 16 +++++++++-------
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/formComp/formComp.tsx b/client/packages/lowcoder/src/comps/comps/formComp/formComp.tsx
index e0fce300c..84a7b7156 100644
--- a/client/packages/lowcoder/src/comps/comps/formComp/formComp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/formComp/formComp.tsx
@@ -208,13 +208,17 @@ const FormBaseComp = (function () {
     );
   })
     .setPropertyViewFn((children) => {
+      const editorContext = useContext(EditorContext);
+      const isLogicMode = editorContext.editorModeStatus === "logic" || editorContext.editorModeStatus === "both";
+      const isLayoutMode = editorContext.editorModeStatus === "layout" || editorContext.editorModeStatus === "both";
+      
       return (
         <>
           <Section name={sectionNames.basic}>
             {children.resetAfterSubmit.propertyView({ label: trans("formComp.resetAfterSubmit") })}
           </Section>
 
-          {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && (
+          {isLogicMode && (
             <><Section name={sectionNames.interaction}>
                 {children.onEvent.getPropertyView()}
                 {disabledPropertyView(children)}
@@ -225,7 +229,7 @@ const FormBaseComp = (function () {
             </>
           )}
 
-          {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && (
+          {isLayoutMode && (
             <>
               <Section name={sectionNames.layout}>
                 {children.container.getPropertyView()}
@@ -233,14 +237,14 @@ const FormBaseComp = (function () {
             </>
           )}
 
-          {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && (
+          {isLogicMode && (
             <Section name={sectionNames.advanced}>
               {children.initialData.propertyView({ label: trans("formComp.initialData") })}
               {children.invalidFormMessage.propertyView({ label: trans("formComp.invalidFormMessage") })}
             </Section>
           )}
 
-          {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && (
+          {isLayoutMode && (
             <>
               <Section name={sectionNames.style}>
                 {children.container.stylePropertyView()}
@@ -383,9 +387,7 @@ let FormTmpComp = class extends FormBaseComp implements IForm {
       case CompActionTypes.UPDATE_NODES_V2: {
         const ret = super.reduce(action);
         // When the initial value changes, update the form
-        if (ret.children.initialData !== this.children.initialData) {
-          // FIXME: kill setTimeout ?
-          setTimeout(() => {
+          requestAnimationFrame(() => {
             this.dispatch(
               customAction<SetDataAction>(
                 {
@@ -396,7 +398,6 @@ let FormTmpComp = class extends FormBaseComp implements IForm {
               )
             );
           });
-        }
         return ret;
       }
       case CompActionTypes.CUSTOM:
diff --git a/client/packages/lowcoder/src/redux/sagas/orgSagas.ts b/client/packages/lowcoder/src/redux/sagas/orgSagas.ts
index dd64bf1c9..e4157abde 100644
--- a/client/packages/lowcoder/src/redux/sagas/orgSagas.ts
+++ b/client/packages/lowcoder/src/redux/sagas/orgSagas.ts
@@ -367,13 +367,15 @@ export function* fetchWorkspacesSaga(action: ReduxAction<{page: number, pageSize
       const apiData = response.data.data;
       
       // Transform orgId/orgName to match Org interface
-      const transformedItems = apiData.data.map(item => ({
-        id: item.orgView.orgId,
-        name: item.orgView.orgName,
-        createdAt: item.orgView.createdAt,
-        updatedAt: item.orgView.updatedAt,
-        isCurrentOrg: item.isCurrentOrg,
-      }));
+      const transformedItems = apiData.data
+        .filter(item => item.orgView && item.orgView.orgId) 
+        .map(item => ({
+          id: item.orgView.orgId,
+          name: item.orgView.orgName,
+          createdAt: item.orgView.createdAt,
+          updatedAt: item.orgView.updatedAt,
+          isCurrentOrg: item.isCurrentOrg,
+        }));
         
       yield put({
         type: ReduxActionTypes.FETCH_WORKSPACES_SUCCESS,
