Skip to content

Commit 7ad588b

Browse files
committed
Improve checks.
1 parent 6e0b8f3 commit 7ad588b

File tree

1 file changed

+42
-23
lines changed

1 file changed

+42
-23
lines changed

dash/dash-renderer/src/TreeContainer.js

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
equals,
1212
isEmpty,
1313
isNil,
14+
has,
1415
keys,
1516
map,
1617
mergeRight,
@@ -71,6 +72,15 @@ function createElement(element, props, extraProps, children) {
7172
return React.createElement(element, allProps, children);
7273
}
7374

75+
function isDryComponent(obj) {
76+
return (
77+
type(obj) === 'Object' &&
78+
has('type', obj) &&
79+
has('namespace', obj) &&
80+
has('props', obj)
81+
);
82+
}
83+
7484
const TreeContainer = memo(props => (
7585
<DashContext.Consumer>
7686
{context => (
@@ -212,28 +222,33 @@ class BaseTreeContainer extends Component {
212222
if (childrenProp.startsWith('[]')) {
213223
const frontPath = path[0].slice(2);
214224
node = _dashprivate_layout.props[frontPath];
215-
if (!node) {
225+
if (node === undefined) {
216226
return;
217227
}
218228
nodeValue = node.map((n, i) => ({
219229
...n,
220-
[path[1]]: this.createContainer(
221-
this.props,
222-
n[path[1]],
223-
concat(this.props._dashprivate_path, [
224-
'props',
225-
frontPath,
226-
i,
227-
path[1]
228-
])
229-
)
230+
[path[1]]: isDryComponent(n[path[1]])
231+
? this.createContainer(
232+
this.props,
233+
n[path[1]],
234+
concat(this.props._dashprivate_path, [
235+
'props',
236+
frontPath,
237+
i,
238+
path[1]
239+
])
240+
)
241+
: n
230242
}));
231243
path = [frontPath];
232244
} else {
233245
node = rpath(path, _dashprivate_layout.props);
234-
if (!node) {
246+
if (node === undefined) {
235247
return;
236248
}
249+
if (!isDryComponent(node)) {
250+
return node;
251+
}
237252
nodeValue = this.createContainer(
238253
this.props,
239254
node,
@@ -247,23 +262,27 @@ class BaseTreeContainer extends Component {
247262
return assocPath(path, nodeValue);
248263
}
249264
const node = _dashprivate_layout.props[childrenProp];
250-
if (node) {
265+
if (node !== undefined) {
251266
if (Array.isArray(node)) {
252267
return assoc(
253268
childrenProp,
254269
node.map((n, i) =>
255-
this.createContainer(
256-
this.props,
257-
n,
258-
concat(this.props._dashprivate_path, [
259-
'props',
260-
childrenProp,
261-
i
262-
])
263-
)
270+
isDryComponent(n)
271+
? this.createContainer(
272+
this.props,
273+
n,
274+
concat(
275+
this.props._dashprivate_path,
276+
['props', childrenProp, i]
277+
)
278+
)
279+
: n
264280
)
265281
);
266282
}
283+
if (!isDryComponent(node)) {
284+
return;
285+
}
267286
return assoc(
268287
childrenProp,
269288
this.createContainer(
@@ -277,7 +296,7 @@ class BaseTreeContainer extends Component {
277296
);
278297
}
279298
})
280-
.filter(e => e)
299+
.filter(e => e !== undefined)
281300
)(_dashprivate_layout.props);
282301

283302
if (type(props.id) === 'Object') {

0 commit comments

Comments
 (0)