Skip to content

Commit 9003007

Browse files
fixed global data variables lost while navigating apps
1 parent a59626b commit 9003007

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

client/packages/lowcoder/src/comps/generators/hookToComp.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function hookToComp(useHookFn: () => JSONObject) {
1313
}),
1414
(comp) => {
1515
const hookValue = useHookFn();
16+
1617
useEffect(() => {
1718
comp.children.value.dispatchChangeValueAction(hookValue);
1819
}, [hookValue]);
@@ -33,8 +34,10 @@ export function hookToStateComp(useHookFn: () => JSONObject) {
3334
(comp) => {
3435
const hookValue = useHookFn();
3536
useEffect(() => {
36-
comp.children.stateValue.dispatchChangeValueAction(hookValue);
37-
}, [hookValue]);
37+
if (hookValue !== comp.children.stateValue.getView()) {
38+
comp.children.stateValue.dispatchChangeValueAction(hookValue);
39+
}
40+
}, []);
3841
return null;
3942
}
4043
);

client/packages/lowcoder/src/pages/editor/appEditorInternal.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function useSaveComp(
4444
const dispatch = useDispatch();
4545
const [prevComp, setPrevComp] = useState<Comp>();
4646
const [prevJsonStr, setPrevJsonStr] = useState<string>();
47+
const [prevAppId, setPrevAppId] = useState<string>();
4748

4849
useEffect(() => {
4950
if (readOnly || blockEditing) {
@@ -54,7 +55,7 @@ function useSaveComp(
5455
}
5556
const curJson = comp.toJsonValue();
5657
const curJsonStr = JSON.stringify(curJson);
57-
if (prevJsonStr === curJsonStr) {
58+
if (prevJsonStr === curJsonStr || (Boolean(prevAppId) && prevAppId !== applicationId)) {
5859
return;
5960
}
6061
// the first time is a normal change, the latter is the manual update
@@ -70,7 +71,8 @@ function useSaveComp(
7071
}
7172
setPrevComp(comp);
7273
setPrevJsonStr(curJsonStr);
73-
}, [comp, applicationId, prevComp, prevJsonStr, readOnly, dispatch]);
74+
setPrevAppId(applicationId);
75+
}, [comp, prevAppId, applicationId, prevComp, prevJsonStr, readOnly, dispatch]);
7476
}
7577

7678
interface AppEditorInternalViewProps {

0 commit comments

Comments
 (0)