Skip to content

Commit 65ffabd

Browse files
committed
memo wrapper, merge loading state selector, add back _dashprivate_layout
1 parent 378fec3 commit 65ffabd

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

dash/dash-renderer/src/wrapper/DashWrapper.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useMemo, useCallback} from 'react';
1+
import React, {useMemo, useCallback, memo} from 'react';
22
import {
33
path,
44
concat,
@@ -29,8 +29,6 @@ import isSimpleComponent from '../isSimpleComponent';
2929
import {
3030
selectDashProps,
3131
selectDashPropsEqualityFn,
32-
selectLoadingState,
33-
selectLoadingStateEqualityFn,
3432
selectConfig
3533
} from './selectors';
3634
import CheckedComponent from './CheckedComponent';
@@ -51,17 +49,11 @@ function DashWrapper({
5149
const config: DashConfig = useSelector(selectConfig);
5250

5351
// Select both the component and it's props.
54-
const [component, componentProps] = useSelector(
52+
const [component, componentProps, loading_state] = useSelector(
5553
selectDashProps(componentPath),
5654
selectDashPropsEqualityFn
5755
);
5856

59-
// Loading state for dcc.Loading
60-
const loading_state = useSelector(
61-
selectLoadingState(componentPath),
62-
selectLoadingStateEqualityFn
63-
);
64-
6557
const setProps = (newProps: UpdatePropsPayload) => {
6658
const {id} = componentProps;
6759
const {_dash_error, ...restProps} = newProps;
@@ -172,7 +164,8 @@ function DashWrapper({
172164

173165
const extraProps = {
174166
loading_state,
175-
setProps
167+
setProps,
168+
_dashprivate_layout: component
176169
};
177170

178171
const element = useMemo(() => Registry.resolve(component), [component]);
@@ -422,4 +415,10 @@ function DashWrapper({
422415
);
423416
}
424417

425-
export default DashWrapper;
418+
export default memo(
419+
DashWrapper,
420+
(prevProps, nextProps) =>
421+
JSON.stringify(prevProps._dashprivate_path) ===
422+
JSON.stringify(nextProps._dashprivate_path) &&
423+
prevProps._dashprivate_error === nextProps._dashprivate_error
424+
);

dash/dash-renderer/src/wrapper/selectors.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ import {
88
} from '../types/component';
99
import {getLoadingState} from './wrapping';
1010

11-
type SelectDashProps = [DashComponent, BaseDashProps];
11+
type SelectDashProps = [DashComponent, BaseDashProps, DashLoadingState];
1212

1313
export const selectDashProps =
1414
(componentPath: DashLayoutPath) =>
1515
(state: any): SelectDashProps => {
1616
const c = path(componentPath, state.layout) as DashComponent;
17-
return [c, c.props];
17+
const loading_state = getLoadingState(
18+
c,
19+
componentPath,
20+
state.loadingMap
21+
);
22+
return [c, c.props, loading_state];
1823
};
1924

2025
export function selectDashPropsEqualityFn(

0 commit comments

Comments
 (0)