Skip to content

Minimize rerendering #1147

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 6 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { SHARE_TITLE } from "../../constants/apiConstants";
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances";
import { default as Divider } from "antd/es/divider";

export const AppPermissionDialog = (props: {
export const AppPermissionDialog = React.memo((props: {
applicationId: string;
visible: boolean;
onVisibleChange: (visible: boolean) => void;
Expand Down Expand Up @@ -148,7 +148,7 @@ export const AppPermissionDialog = (props: {
}
/>
);
};
});

const InviteInputBtn = styled.div`
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
DEFAULT_GRID_COLUMNS,
DEFAULT_ROW_HEIGHT,
} from "layout/calculateUtils";
import _ from "lodash";
import _, { isEqual } from "lodash";
import {
ActionExtraInfo,
changeChildAction,
Expand Down Expand Up @@ -313,7 +313,7 @@ const ItemWrapper = styled.div<{ $disableInteract?: boolean }>`
pointer-events: ${(props) => (props.$disableInteract ? "none" : "unset")};
`;

const GridItemWrapper = React.forwardRef(
const GridItemWrapper = React.memo(React.forwardRef(
(
props: React.PropsWithChildren<HTMLAttributes<HTMLDivElement>>,
ref: React.ForwardedRef<HTMLDivElement>
Expand All @@ -326,11 +326,11 @@ const GridItemWrapper = React.forwardRef(
</ItemWrapper>
);
}
);
));

type GirdItemViewRecord = Record<string, GridItem>;

export function InnerGrid(props: ViewPropsWithSelect) {
export const InnerGrid = React.memo((props: ViewPropsWithSelect) => {
const {
positionParams,
rowCount = Infinity,
Expand All @@ -348,11 +348,13 @@ export function InnerGrid(props: ViewPropsWithSelect) {

// Falk: TODO: Here we can define the inner grid columns dynamically
//Added By Aqib Mirza
const defaultGrid =
horizontalGridCells ||
const defaultGrid = useMemo(() => {
return horizontalGridCells ||
currentTheme?.gridColumns ||
defaultTheme?.gridColumns ||
"12";
}, [horizontalGridCells, currentTheme?.gridColumns, defaultTheme?.gridColumns]);

/////////////////////
const isDroppable =
useContext(IsDroppable) && (_.isNil(props.isDroppable) || props.isDroppable) && !readOnly;
Expand Down Expand Up @@ -385,7 +387,7 @@ export function InnerGrid(props: ViewPropsWithSelect) {

const canAddSelect = useMemo(
() => _.size(containerSelectNames) === _.size(editorState.selectedCompNames),
[containerSelectNames, editorState]
[containerSelectNames, editorState.selectedCompNames]
);

const dispatchPositionParamsTimerRef = useRef(0);
Expand Down Expand Up @@ -432,16 +434,21 @@ export function InnerGrid(props: ViewPropsWithSelect) {
onPositionParamsChange,
onRowCountChange,
positionParams,
props,
props.dispatch,
props.containerPadding,
]
);
const setSelectedNames = useCallback(
(names: Set<string>) => {
editorState.setSelectedCompNames(names);
},
[editorState]
[editorState.setSelectedCompNames]
);
const { width, ref } = useResizeDetector({ onResize, handleHeight: isRowCountLocked });

const { width, ref } = useResizeDetector({
onResize,
handleHeight: isRowCountLocked,
});

const itemViewRef = useRef<GirdItemViewRecord>({});
const itemViews = useMemo(() => {
Expand All @@ -464,9 +471,10 @@ export function InnerGrid(props: ViewPropsWithSelect) {
const clickItem = useCallback(
(
e: React.MouseEvent<HTMLDivElement,
globalThis.MouseEvent>, name: string
globalThis.MouseEvent>,
name: string,
) => selectItem(e, name, canAddSelect, containerSelectNames, setSelectedNames),
[canAddSelect, containerSelectNames, setSelectedNames]
[selectItem, canAddSelect, containerSelectNames, setSelectedNames]
);

useEffect(() => {
Expand Down Expand Up @@ -555,7 +563,9 @@ export function InnerGrid(props: ViewPropsWithSelect) {
{itemViews}
</ReactGridLayout>
);
}
}, (prevProps, newProps) => {
return isEqual(prevProps, newProps);
});

function selectItem(
e: MouseEvent<HTMLDivElement>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EditorContext } from "comps/editorState";
import { EditorContainer } from "pages/common/styledComponent";
import { Profiler, useContext, useRef, useState } from "react";
import React, { Profiler, useContext, useRef, useState } from "react";
import styled from "styled-components";
import { profilerCallback } from "util/cacheUtils";
import {
Expand All @@ -20,6 +20,7 @@ import { CanvasContainerID } from "constants/domLocators";
import { CNRootContainer } from "constants/styleSelectors";
import { ScrollBar } from "lowcoder-design";
import { defaultTheme } from "@lowcoder-ee/constants/themeConstants";
import { isEqual } from "lodash";

// min-height: 100vh;

Expand Down Expand Up @@ -72,7 +73,7 @@ function getDragSelectedNames(

const EmptySet = new Set<string>();

export function CanvasView(props: ContainerBaseProps) {
export const CanvasView = React.memo((props: ContainerBaseProps) => {
const editorState = useContext(EditorContext);
const [dragSelectedComps, setDragSelectedComp] = useState(EmptySet);
const scrollContainerRef = useRef(null);
Expand Down Expand Up @@ -166,4 +167,6 @@ export function CanvasView(props: ContainerBaseProps) {
</EditorContainer>
</CanvasContainer>
);
}
}, (prevProps, newProps) => {
return isEqual(prevProps, newProps);
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const InitialState = {
startPoint: undefined,
};

export class DragSelector extends React.Component<SectionProps, SectionState> {
class DragSelectorComp extends React.Component<SectionProps, SectionState> {
private readonly selectAreaRef: React.RefObject<HTMLDivElement>;

constructor(props: SectionProps) {
Expand Down Expand Up @@ -178,3 +178,5 @@ export class DragSelector extends React.Component<SectionProps, SectionState> {
};
}
}

export const DragSelector = React.memo(DragSelectorComp);
8 changes: 6 additions & 2 deletions client/packages/lowcoder/src/comps/comps/rootComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
import RefTreeComp from "./refTreeComp";
import { ExternalEditorContext } from "util/context/ExternalEditorContext";
import { useUserViewMode } from "util/hooks";
import React from "react";
import { isEqual } from "lodash";

const EditorView = lazy(
() => import("pages/editor/editorView"),
Expand All @@ -55,7 +57,7 @@ const childrenMap = {
preload: PreloadComp,
};

function RootView(props: RootViewProps) {
const RootView = React.memo((props: RootViewProps) => {
const previewTheme = useContext(ThemeContext);
const { comp, isModuleRoot, ...divProps } = props;
const [editorState, setEditorState] = useState<EditorState>();
Expand Down Expand Up @@ -143,7 +145,9 @@ function RootView(props: RootViewProps) {
</PropertySectionContext.Provider>
</div>
);
}
}, (prevProps, nextProps) => {
return isEqual(prevProps, nextProps);
});

/**
* Root Comp
Expand Down
21 changes: 10 additions & 11 deletions client/packages/lowcoder/src/comps/generators/uiCompBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export type NewChildren<ChildrenCompMap extends Record<string, Comp<unknown>>> =
version: InstanceType<typeof StringControl>;
};

export function HidableView(props: {
export const HidableView = React.memo((props: {
children: JSX.Element | React.ReactNode;
hidden: boolean;
}) {
}) => {
const { readOnly } = useContext(ExternalEditorContext);
if (readOnly) {
return <>{props.children}</>;
Expand All @@ -64,15 +64,15 @@ export function HidableView(props: {
</>
);
}
}
})

export function ExtendedPropertyView<
export const ExtendedPropertyView = React.memo(<
ChildrenCompMap extends Record<string, Comp<unknown>>,
>(props: {
children: JSX.Element | React.ReactNode,
childrenMap: NewChildren<ChildrenCompMap>
}
) {
) => {
const [compVersions, setCompVersions] = useState(['latest']);
const [compName, setCompName] = useState('');
const editorState = useContext(EditorContext);
Expand Down Expand Up @@ -129,7 +129,7 @@ export function ExtendedPropertyView<
)}
</>
);
}
});

export function uiChildren<
ChildrenCompMap extends Record<string, Comp<unknown>>,
Expand Down Expand Up @@ -275,11 +275,11 @@ export const DisabledContext = React.createContext<boolean>(false);
/**
* Guaranteed to be in a react component, so that react hooks can be used internally
*/
function UIView(props: {
const UIView = React.memo((props: {
innerRef: React.RefObject<HTMLDivElement>;
comp: any;
viewFn: any;
}) {
}) => {
const comp = props.comp;
const childrenProps = childrenToProps(comp.children);
const childrenJsonProps = comp.toJsonValue();
Expand Down Expand Up @@ -397,13 +397,12 @@ function UIView(props: {
width: '100%',
height: '100%',
margin: '0px',
padding:getPadding()

padding: getPadding()
}}
>
<HidableView hidden={childrenProps.hidden as boolean}>
{props.viewFn(childrenProps, comp.dispatch)}
</HidableView>
</div>
);
}
});
6 changes: 6 additions & 0 deletions client/packages/lowcoder/src/index.sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import * as styledNameExports from "styled-components";
import styledDefault from "styled-components";
export * as styledm from "styled-components";
export * from "comps/comps/containerBase/containerCompBuilder";
export * from "comps/comps/containerBase/iContainer";
export * from "comps/comps/containerBase/utils";
export * from "comps/comps/containerBase/simpleContainerComp";
export * from "comps/utils/backgroundColorContext";
export { getData } from "comps/comps/listViewComp/listViewUtils";
export { gridItemCompToGridItems, InnerGrid } from "comps/comps/containerComp/containerView";
export type { ContainerBaseProps } from "comps/comps/containerComp/containerView";

export { Layers } from "constants/Layers";
export * from "comps/controls/eventHandlerControl";
Expand Down Expand Up @@ -97,6 +101,7 @@ export * from "comps/controls/simpleStringControl";
export * from "comps/controls/stringSimpleControl";
export * from "comps/controls/styleControl";
export * from "comps/controls/styleControlConstants";
export * from "comps/controls/slotControl";

// generators
export * from "comps/generators/changeDataType";
Expand All @@ -114,6 +119,7 @@ export * from "comps/generators/withExposing";
export * from "comps/generators/withIsLoading";
export * from "comps/generators/withMethodExposing";
export * from "comps/generators/withType";
export * from "comps/generators/controlCompBuilder";

export * from "appView/bootstrapAt";
export * from "appView/LowcoderAppView";
Expand Down
4 changes: 2 additions & 2 deletions client/packages/lowcoder/src/layout/compSelectionWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const HiddenIcon = styled(CloseEyeIcon)`
}
`;

export const CompSelectionWrapper = (props: {
export const CompSelectionWrapper = React.memo((props: {
id?: string;
compType: UICompType;
className?: string;
Expand Down Expand Up @@ -376,4 +376,4 @@ export const CompSelectionWrapper = (props: {
</SelectableDiv>
</div>
);
};
});
Loading
Loading