Skip to content

Commit 9fa2474

Browse files
fixed app dsl saved again another app on rapid navigation + fixed global data variables lost b/w app navigation
1 parent 335b513 commit 9fa2474

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { JSONObject } from "util/jsonTypes";
22
import { simpleMultiComp, stateComp, valueComp, withViewFn } from "comps/generators";
33
import { withSimpleExposing } from "comps/generators/withExposing";
4-
import { useEffect } from "react";
4+
import { useEffect, useMemo } from "react";
5+
import { isEqual } from "lodash";
56

67
/**
78
* Enter a react hook and return a comp that exposes the data and methods provided by the hook
@@ -33,11 +34,11 @@ export function hookToStateComp(useHookFn: () => JSONObject) {
3334
}),
3435
(comp) => {
3536
const hookValue = useHookFn();
36-
useEffect(() => {
37-
if (hookValue !== comp.children.stateValue.getView()) {
38-
comp.children.stateValue.dispatchChangeValueAction(hookValue);
39-
}
40-
}, []);
37+
const stateValue = useMemo(() => comp.children.stateValue.getView(), [comp.children.stateValue]);
38+
39+
if (!isEqual(hookValue, stateValue)) {
40+
comp.children.stateValue.dispatchChangeValueAction(hookValue);
41+
}
4142
return null;
4243
}
4344
);

client/packages/lowcoder/src/comps/hooks/themeComp.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { withMethodExposing } from "comps/generators/withMethodExposing";
66
import { getGlobalSettings } from "comps/utils/globalSettings";
77
import { getCurrentTheme } from "comps/utils/themeUtil";
88
import { trans } from "i18n";
9+
import { isEqual } from "lodash";
910
import { useContext, useEffect, useMemo } from "react";
1011
import { getThemeList } from "redux/selectors/commonSettingSelectors";
1112
import { useSelector } from "redux/store/store";
@@ -47,12 +48,28 @@ let ThemeTempComp = withViewFn(
4748
const editorState = useContext(EditorContext);
4849
const appThemeId = editorState?.getAppSettings().themeId;
4950
const currentTheme = getCurrentTheme(themeList, appThemeId);
50-
useEffect(() => {
51+
const stateValue = useMemo(() => comp.children.stateValue.getView(), [comp.children.stateValue]);
52+
53+
const themeValue = useMemo(() => {
54+
if (
55+
currentTheme?.id !== stateValue.id
56+
|| currentTheme?.id !== stateValue.name
57+
|| !isEqual(themeList, stateValue.allThemes)
58+
) {
59+
return {
60+
...exposingTheme(currentTheme),
61+
allThemes: themeList.map((t) => exposingTheme(t)),
62+
}
63+
}
64+
return stateValue;
65+
}, [themeList, currentTheme, stateValue])
66+
67+
if (!isEqual(themeValue, stateValue)) {
5168
comp.children.stateValue.dispatchChangeValueAction({
5269
...exposingTheme(currentTheme),
5370
allThemes: themeList.map((t) => exposingTheme(t)),
54-
});
55-
}, [themeList, currentTheme]);
71+
})
72+
}
5673
return null;
5774
}
5875
);

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const AppEditor = React.memo(() => {
8888
const [isDataSourcePluginRegistered, setIsDataSourcePluginRegistered] = useState(false);
8989
const [appError, setAppError] = useState('');
9090
const [blockEditing, setBlockEditing] = useState<boolean>(false);
91+
const [fetchingAppDetails, setFetchingAppDetails] = useState<boolean>(false);
9192

9293
setGlobalSettings({ applicationId, isViewMode: paramViewMode === "view" });
9394

@@ -174,6 +175,7 @@ const AppEditor = React.memo(() => {
174175
}, [dispatch, fetchOrgGroupsFinished, orgId]);
175176

176177
const fetchApplication = useCallback(() => {
178+
setFetchingAppDetails(true);
177179
dispatch(
178180
fetchApplicationInfo({
179181
type: viewMode,
@@ -190,9 +192,11 @@ const AppEditor = React.memo(() => {
190192
});
191193
setAppInfo(info);
192194
fetchJSDataSourceByApp();
195+
setFetchingAppDetails(false);
193196
},
194197
onError: (errorMessage) => {
195198
setAppError(errorMessage);
199+
setFetchingAppDetails(false);
196200
}
197201
})
198202
);
@@ -249,16 +253,21 @@ const AppEditor = React.memo(() => {
249253
</Suspense>
250254
) : (
251255
<Suspense fallback={<EditorSkeletonView />}>
252-
<AppEditorInternalView
253-
appInfo={appInfo}
254-
readOnly={readOnly}
255-
blockEditing={blockEditing}
256-
loading={
257-
!fetchOrgGroupsFinished || !isDataSourcePluginRegistered || isCommonSettingsFetching
258-
}
259-
compInstance={compInstance}
260-
fetchApplication={fetchApplication}
261-
/>
256+
{fetchingAppDetails
257+
? <EditorSkeletonView />
258+
: (
259+
<AppEditorInternalView
260+
appInfo={appInfo}
261+
readOnly={readOnly}
262+
blockEditing={blockEditing}
263+
loading={
264+
!fetchOrgGroupsFinished || !isDataSourcePluginRegistered || isCommonSettingsFetching
265+
}
266+
compInstance={compInstance}
267+
fetchApplication={fetchApplication}
268+
/>
269+
)
270+
}
262271
</Suspense>
263272
)}
264273
</ErrorBoundary>

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,21 @@ function useSaveComp(
5555
}
5656
const curJson = comp.toJsonValue();
5757
const curJsonStr = JSON.stringify(curJson);
58-
if (prevJsonStr === curJsonStr || (Boolean(prevAppId) && prevAppId !== applicationId)) {
58+
59+
60+
if (!Boolean(prevAppId) && Boolean(applicationId)) {
61+
return setPrevAppId(applicationId);
62+
}
63+
if (prevAppId !== applicationId) {
64+
return setPrevAppId(applicationId);
65+
}
66+
if (!Boolean(prevJsonStr) && Boolean(curJsonStr)) {
67+
return setPrevJsonStr(curJsonStr);
68+
}
69+
if (prevJsonStr === curJsonStr) {
5970
return;
6071
}
72+
6173
// the first time is a normal change, the latter is the manual update
6274
if (prevComp) {
6375
dispatch(

0 commit comments

Comments
 (0)