Skip to content

Commit 3ade208

Browse files
committed
adjustments based on feedback
1 parent 96166c8 commit 3ade208

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

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

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -71,33 +71,33 @@ function DashWrapper({
7171
const memoizedKeys: MutableRefObject<MemoizedKeysType> = useRef({});
7272
const memoizedProps: MutableRefObject<MemoizedPropsType> = useRef({});
7373
const newRender = useRef(false);
74+
let renderComponent: any = null;
75+
let renderComponentProps: any = null;
76+
let renderH: any = null;
7477

7578
// Get the config for the component as props
7679
const config: DashConfig = useSelector(selectConfig);
7780

78-
// Select both the component and it's props.
79-
// eslint-disable-next-line prefer-const
80-
let [component, componentProps, h, changedProps, renderType] = useSelector(
81-
selectDashProps(componentPath),
82-
selectDashPropsEqualityFn
83-
);
81+
// Select component and it's props, along with render hash, changed props and the reason for render
82+
const [component, componentProps, h, changedProps, renderType] =
83+
useSelector(selectDashProps(componentPath), selectDashPropsEqualityFn);
84+
85+
renderComponent = component;
86+
renderComponentProps = componentProps;
87+
renderH = h;
8488

85-
/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unused-vars */
86-
// @ts-ignore
87-
const newlyRendered: any = useMemo(() => {
89+
useMemo(() => {
8890
if (_newRender) {
8991
memoizedProps.current = {};
9092
newRender.current = true;
91-
h = 0;
93+
renderH = 0;
9294
if (h in memoizedKeys.current) {
9395
delete memoizedKeys.current[h];
9496
}
9597
} else {
9698
newRender.current = false;
9799
}
98-
return newRender.current;
99100
}, [_newRender]);
100-
/* eslint-enable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unused-vars */
101101

102102
memoizedProps.current = componentProps;
103103

@@ -163,8 +163,8 @@ function DashWrapper({
163163

164164
const createContainer = useCallback(
165165
(container, containerPath, _childNewRender, key = undefined) => {
166-
if (isSimpleComponent(component)) {
167-
return component;
166+
if (isSimpleComponent(container)) {
167+
return container;
168168
}
169169
return (
170170
<DashWrapper
@@ -220,7 +220,7 @@ function DashWrapper({
220220
...extras
221221
} as {[key: string]: any};
222222

223-
if (checkRenderTypeProp(component)) {
223+
if (checkRenderTypeProp(renderComponent)) {
224224
extraProps['dashRenderType'] = newRender.current
225225
? 'parent'
226226
: changedProps
@@ -246,7 +246,7 @@ function DashWrapper({
246246
.replace('[]', '')
247247
.replace('{}', '') in changedProps ||
248248
newRender.current ||
249-
!h
249+
!renderH
250250
) {
251251
childNewRender = {};
252252
}
@@ -444,22 +444,27 @@ function DashWrapper({
444444

445445
const hydrateFunc = () => {
446446
if (newRender.current) {
447-
component = _passedComponent;
448-
componentProps = _passedComponent?.props;
447+
renderComponent = _passedComponent;
448+
renderComponentProps = _passedComponent?.props;
449449
}
450-
if (!component) {
450+
if (!renderComponent) {
451451
return null;
452452
}
453453

454-
const element = Registry.resolve(component);
455-
const hydratedProps = setHydratedProps(component, componentProps);
454+
const element = Registry.resolve(renderComponent);
455+
const hydratedProps = setHydratedProps(
456+
renderComponent,
457+
renderComponentProps
458+
);
456459

457460
let hydratedChildren: any;
458-
if (componentProps.children !== undefined) {
461+
if (renderComponentProps.children !== undefined) {
459462
hydratedChildren = wrapChildrenProp(
460-
componentProps.children,
463+
renderComponentProps.children,
461464
['children'],
462-
!h || newRender.current || 'children' in changedProps ? {} : 0
465+
!renderH || newRender.current || 'children' in changedProps
466+
? {}
467+
: 0
463468
);
464469
}
465470
newRender.current = false;
@@ -468,7 +473,7 @@ function DashWrapper({
468473
<CheckedComponent
469474
element={element}
470475
props={hydratedProps}
471-
component={component}
476+
component={renderComponent}
472477
>
473478
{createElement(
474479
element,
@@ -483,14 +488,14 @@ function DashWrapper({
483488
};
484489

485490
let hydrated = null;
486-
if (h in memoizedKeys.current && !newRender.current) {
487-
hydrated = React.isValidElement(memoizedKeys.current[h])
488-
? memoizedKeys.current[h]
491+
if (renderH in memoizedKeys.current && !newRender.current) {
492+
hydrated = React.isValidElement(memoizedKeys.current[renderH])
493+
? memoizedKeys.current[renderH]
489494
: null;
490495
}
491496
if (!hydrated) {
492497
hydrated = hydrateFunc();
493-
memoizedKeys.current = {[h]: hydrated};
498+
memoizedKeys.current = {[renderH]: hydrated};
494499
}
495500

496501
return component ? (

0 commit comments

Comments
 (0)