Skip to content

Added memoization to minimize re-rendering #1159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added fallback for left-panel, right-panel and bottom-panel
  • Loading branch information
raheeliftikhar5 committed Sep 12, 2024
commit 6ebb066b7fee0cf5ad5d7ca8b3b19b61599b94b5
1 change: 0 additions & 1 deletion client/packages/lowcoder/src/layout/gridLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,6 @@ const LayoutContainer = styled.div<{
}`}
`;

// export const ReactGridLayout = React.memo(GridLayout);
export const ReactGridLayout = React.memo(GridLayout);

function moveOrResize(
Expand Down
2 changes: 1 addition & 1 deletion client/packages/lowcoder/src/pages/common/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export default function Header(props: HeaderProps) {
size="small"
>
{editorModeOptions.map((option) => (
<Tooltip title={option.tooltip}>
<Tooltip key={option.key} title={option.tooltip}>
<Radio.Button key={option.key} value={option.value}>
{option.label}
</Radio.Button>
Expand Down
7 changes: 5 additions & 2 deletions client/packages/lowcoder/src/pages/editor/AppEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {ErrorBoundary, FallbackProps} from 'react-error-boundary';
import { ALL_APPLICATIONS_URL } from "@lowcoder-ee/constants/routesURL";
import history from "util/history";
import Flex from "antd/es/flex";
import React from "react";

const AppSnapshot = lazy(() => {
return import("pages/editor/appSnapshot")
Expand All @@ -42,7 +43,7 @@ const AppEditorInternalView = lazy(
.then(moduleExports => ({default: moduleExports.AppEditorInternalView}))
);

export default function AppEditor() {
const AppEditor = React.memo(() => {
const showAppSnapshot = useSelector(showAppSnapshotSelector);
const params = useParams<AppPathParams>();
const isUserViewModeCheck = useUserViewMode();
Expand Down Expand Up @@ -190,4 +191,6 @@ export default function AppEditor() {
)}
</ErrorBoundary>
);
}
});

export default AppEditor;
5 changes: 3 additions & 2 deletions client/packages/lowcoder/src/pages/editor/appSnapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { TopHeaderHeight } from "constants/style";
import { SnapshotItemProps, SnapshotList } from "../../components/SnapshotList";
import { trans } from "i18n";
import EditorSkeletonView from "./editorSkeletonView";
import React from "react";

const AppEditorInternalView = lazy(
() => import("pages/editor/appEditorInternal")
Expand Down Expand Up @@ -134,7 +135,7 @@ const PAGE_SIZE = 10;
const CURRENT_ITEM_KEY = "current_key";
const TIME_FORMAT = trans("history.timeFormat");

export function AppSnapshot(props: { currentAppInfo: AppSummaryInfo }) {
export const AppSnapshot = React.memo((props: { currentAppInfo: AppSummaryInfo }) => {
const { currentAppInfo } = props;
const currentDsl = currentAppInfo.dsl;
const dispatch = useDispatch();
Expand Down Expand Up @@ -289,4 +290,4 @@ export function AppSnapshot(props: { currentAppInfo: AppSummaryInfo }) {
</AppSnapshotPanel>
</Suspense>
);
}
});
131 changes: 72 additions & 59 deletions client/packages/lowcoder/src/pages/editor/editorView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ import {
import { isAggregationApp } from "util/appUtils";
import EditorSkeletonView from "./editorSkeletonView";
import { getCommonSettings } from "@lowcoder-ee/redux/selectors/commonSettingSelectors";
import { isEqual } from "lodash";
import { isEqual, noop } from "lodash";
import { BottomSkeleton } from "./bottom/BottomContent";

const LeftContent = lazy(
() => import('./LeftContent')
Expand Down Expand Up @@ -374,6 +375,23 @@ function EditorView(props: EditorViewProps) {

const hideBodyHeader = useTemplateViewMode() || (isViewMode && (!showHeaderInPublic || !commonSettings.showHeaderInPublicApps));

const uiCompView = useMemo(() => {
if (showAppSnapshot) {
return (
<ViewBody $hideBodyHeader={hideBodyHeader} $height={height}>
<EditorContainer>{uiComp.getView()}</EditorContainer>
</ViewBody>
);
}

return uiComp.getView();
}, [
showAppSnapshot,
hideBodyHeader,
height,
uiComp,
]);

// we check if we are on the public cloud
const isLowCoderDomain = window.location.hostname === 'app.lowcoder.cloud';
const isLocalhost = window.location.hostname === 'localhost';
Expand Down Expand Up @@ -425,16 +443,6 @@ function EditorView(props: EditorViewProps) {

// history mode, display with the right panel, a little trick
const showRight = panelStatus.right || showAppSnapshot;
let uiCompView;
if (showAppSnapshot) {
uiCompView = (
<ViewBody $hideBodyHeader={hideBodyHeader} $height={height}>
<EditorContainer>{uiComp.getView()}</EditorContainer>
</ViewBody>
);
} else {
uiCompView = uiComp.getView();
}

const clickMenu = (params: { key: string }) => {
let left = true;
Expand Down Expand Up @@ -514,46 +522,47 @@ function EditorView(props: EditorViewProps) {
)}
</Sider>
</SiderWrapper>

{panelStatus.left && editorModeStatus !== "layout" && (
<LeftPanel>
{menuKey === SiderKey.State && <LeftContent uiComp={uiComp} />}
{menuKey === SiderKey.Setting && (
<SettingsDiv>
<ScrollBar>
{application &&
!isAggregationApp(
AppUILayoutType[application.applicationType]
) && (
<>
{appSettingsComp.getPropertyView()}
<Divider />
</>
)}
<TitleDiv>{trans("leftPanel.toolbarTitle")}</TitleDiv>
{props.preloadComp.getPropertyView()}
<PreloadDiv
onClick={() => dispatch(
setEditorExternalStateAction({
showScriptsAndStyleModal: true,
})
)}
>
<LeftPreloadIcon />
{trans("leftPanel.toolbarPreload")}
</PreloadDiv>
</ScrollBar>

{props.preloadComp.getJSLibraryPropertyView()}
</SettingsDiv>
)}

{menuKey === SiderKey.Layout && (
<LeftLayersContent uiComp={uiComp} />
)}

</LeftPanel>
)}
<Suspense fallback={null}>
{panelStatus.left && editorModeStatus !== "layout" && (
<LeftPanel>
{menuKey === SiderKey.State && <LeftContent uiComp={uiComp} />}
{menuKey === SiderKey.Setting && (
<SettingsDiv>
<ScrollBar>
{application &&
!isAggregationApp(
AppUILayoutType[application.applicationType]
) && (
<>
{appSettingsComp.getPropertyView()}
<Divider />
</>
)}
<TitleDiv>{trans("leftPanel.toolbarTitle")}</TitleDiv>
{props.preloadComp.getPropertyView()}
<PreloadDiv
onClick={() => dispatch(
setEditorExternalStateAction({
showScriptsAndStyleModal: true,
})
)}
>
<LeftPreloadIcon />
{trans("leftPanel.toolbarPreload")}
</PreloadDiv>
</ScrollBar>

{props.preloadComp.getJSLibraryPropertyView()}
</SettingsDiv>
)}

{menuKey === SiderKey.Layout && (
<LeftLayersContent uiComp={uiComp} />
)}

</LeftPanel>
)}
</Suspense>
<MiddlePanel>
<EditorWrapper className={editorContentClassName}>
<EditorHotKeys disabled={readOnly}>
Expand All @@ -563,15 +572,19 @@ function EditorView(props: EditorViewProps) {
</EditorContainerWithViewMode>
</EditorHotKeys>
</EditorWrapper>
{panelStatus.bottom && editorModeStatus !== "layout" && <Bottom />}
<Suspense fallback={<BottomSkeleton />}>
{panelStatus.bottom && editorModeStatus !== "layout" && <Bottom />}
</Suspense>
</MiddlePanel>
{showRight && (
<RightPanel
uiComp={uiComp}
onCompDrag={onCompDrag}
showPropertyPane={editorState.showPropertyPane}
onTabChange={setShowPropertyPane} />
)}
<Suspense fallback={null}>
{showRight && (
<RightPanel
uiComp={uiComp}
onCompDrag={onCompDrag}
showPropertyPane={editorState.showPropertyPane}
onTabChange={setShowPropertyPane} />
)}
</Suspense>
</Body>
</EditorGlobalHotKeys>
</Height100Div></>
Expand Down