Skip to content

Commit 5c6dbc3

Browse files
committed
adjusting to only render children components as 'new' if it is a new render, there is no hash or the component prop is in the changedProps. There was an issue if the component props had changed from the children, it would think that the parents props had changed and needed to re-render.
1 parent 3bc85d3 commit 5c6dbc3

File tree

6 files changed

+23
-66
lines changed

6 files changed

+23
-66
lines changed

dash/dash-renderer/src/actions/callbacks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ function updateComponent(component_id: any, props: any, cb: ICallbackPayload) {
365365
props,
366366
itempath: componentPath,
367367
component,
368-
config
368+
config,
369+
renderType: 'callback'
369370
})
370371
);
371372
dispatch(notifyObservers({id: component_id, props}));

dash/dash-renderer/src/observers/executedCallbacks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ const observer: IStoreObserverDefinition<IStoreState> = {
7272
props,
7373
source: 'response',
7474
component,
75-
config
75+
config,
76+
renderType: 'callback'
7677
})
7778
);
7879

dash/dash-renderer/src/reducers/reducer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ export const apiRequests = [
3030
function adjustHashes(state, action) {
3131
const actionPath = action.payload.itempath;
3232
const strPath = stringifyPath(actionPath);
33-
const prev = pathOr(0, [strPath, 0], state);
34-
state = assoc(strPath, [prev + 1, action.payload.props], state);
33+
const prev = pathOr(0, [strPath, 'hash'], state);
34+
state = assoc(strPath, {hash: prev + 1,
35+
changedProps: action.payload.props, renderType: action.payload.renderType}, state);
3536
return state;
3637
}
3738

dash/dash-renderer/src/utils/clientsideFunctions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ function set_props(
3030
props,
3131
itempath: componentPath,
3232
component,
33-
config
33+
config,
34+
renderType: 'clientsideApi'
3435
})
3536
);
3637
dispatch(notifyObservers({id: idOrPath, props}));

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

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ import {
1414
dissoc,
1515
assoc,
1616
mapObjIndexed,
17-
type,
18-
reduce,
19-
difference,
20-
intersection,
21-
filter
17+
type
2218
} from 'ramda';
2319
import {useSelector, useDispatch, batch} from 'react-redux';
2420

@@ -39,43 +35,6 @@ import {
3935
import CheckedComponent from './CheckedComponent';
4036
import {DashContextProvider} from './DashContext';
4137

42-
// Define types for the input objects and the output differences
43-
type Dictionary = Record<string, any>;
44-
45-
interface Difference {
46-
obj1: any;
47-
obj2: any;
48-
}
49-
50-
const findDifferences = (
51-
obj1: Dictionary,
52-
obj2: Dictionary
53-
): Record<string, Difference> => {
54-
const commonKeys = intersection(keys(obj1), keys(obj2));
55-
56-
const differingKeys = filter(
57-
(key: string) => !equals(obj1[key], obj2[key]),
58-
commonKeys
59-
) as string[];
60-
61-
const keysOnlyInObj2 = difference(keys(obj2), keys(obj1));
62-
63-
const differences: Record<string, Difference> = reduce(
64-
(acc: Record<string, Difference>, key: string) => {
65-
acc[key] = {obj1: obj1[key], obj2: obj2[key]};
66-
return acc;
67-
},
68-
{},
69-
differingKeys as string[]
70-
);
71-
72-
keysOnlyInObj2.forEach(key => {
73-
differences[key] = {obj1: undefined, obj2: obj2[key]};
74-
});
75-
76-
return differences;
77-
};
78-
7938
type DashWrapperProps = {
8039
/**
8140
* Path of the component in the layout.
@@ -113,7 +72,7 @@ function DashWrapper({
11372

11473
// Select both the component and it's props.
11574
// eslint-disable-next-line prefer-const
116-
let [component, componentProps, h, changedProps] = useSelector(
75+
let [component, componentProps, h, changedProps, renderType] = useSelector(
11776
selectDashProps(componentPath),
11877
selectDashPropsEqualityFn
11978
);
@@ -135,13 +94,6 @@ function DashWrapper({
13594
}, [_newRender]);
13695
/* eslint-enable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unused-vars */
13796

138-
let propDifferences: any = {};
139-
if (memoizedProps.current) {
140-
propDifferences = findDifferences(
141-
memoizedProps.current,
142-
componentProps
143-
);
144-
}
14597
memoizedProps.current = componentProps;
14698

14799
const setProps = (newProps: UpdatePropsPayload) => {
@@ -198,7 +150,8 @@ function DashWrapper({
198150
props: changedProps,
199151
itempath: componentPath,
200152
component,
201-
config
153+
config,
154+
renderType: 'internal'
202155
})
203156
);
204157
});
@@ -261,6 +214,8 @@ function DashWrapper({
261214

262215
const extraProps = {
263216
setProps,
217+
rendertype: newRender.current ? 'parent' : (
218+
changedProps ? renderType : 'parent'),
264219
...extras
265220
};
266221

@@ -277,15 +232,11 @@ function DashWrapper({
277232
const childrenProp: string = childrenProps[i];
278233
let childNewRender = 0;
279234
if (
280-
childrenProp
281-
.split('.')[0]
282-
.replace('[]', '')
283-
.replace('{}', '') in propDifferences ||
284235
childrenProp
285236
.split('.')[0]
286237
.replace('[]', '')
287238
.replace('{}', '') in changedProps ||
288-
newRender.current
239+
newRender.current || !h
289240
) {
290241
childNewRender = Date.now();
291242
}
@@ -498,7 +449,7 @@ function DashWrapper({
498449
hydratedChildren = wrapChildrenProp(
499450
componentProps.children,
500451
['children'],
501-
'children' in propDifferences ||
452+
!h ||
502453
newRender.current ||
503454
'children' in changedProps
504455
? Date.now()

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {DashLayoutPath, DashComponent, BaseDashProps} from '../types/component';
22
import {getComponentLayout, stringifyPath} from './wrapping';
33

4-
type SelectDashProps = [DashComponent, BaseDashProps, number, object];
4+
type SelectDashProps = [DashComponent, BaseDashProps, number, object, string];
55

66
export const selectDashProps =
77
(componentPath: DashLayoutPath) =>
@@ -15,11 +15,13 @@ export const selectDashProps =
1515
const hash = state.layoutHashes[strPath];
1616
let h = 0;
1717
let changedProps: object = {};
18+
let renderType: string = '';
1819
if (hash) {
19-
h = hash[0];
20-
changedProps = hash[1];
20+
h = hash['hash'];
21+
changedProps = hash['changedProps'];
22+
renderType = hash['renderType']
2123
}
22-
return [c, c?.props, h, changedProps];
24+
return [c, c?.props, h, changedProps, renderType];
2325
};
2426

2527
export function selectDashPropsEqualityFn(

0 commit comments

Comments
 (0)