-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
This is part of the "A Pleasant and Productive Developer Experience" objective ❤️
Currently, we don't do any validation on property values of components. So, if you pass in
html.Div([[]])
instead of
html.Div([])
Dash will not raise an error but instead silently fail in the front-end, sometimes but not always showing the notorious "Error loading dependencies" error message.
We have all of the prop-type values available in the component's metadata.json
files, extracted from the component's propTypes
.
For example, here is the Dropdown.react.js
prop types:
https://github.com/plotly/dash-core-components/blob/7c2b102c680d9fe0cb9df61f1682feccfa3ddc05/src/components/Dropdown.react.js#L101-L180
and here is it's associated JSON types:
https://github.com/plotly/dash-core-components/blob/7c2b102c680d9fe0cb9df61f1682feccfa3ddc05/dash_core_components/metadata.json#L810-L946
So, implementing prop type checking would involve:
- Making sure that all component props are sufficiently described. I'm sure that flexible properties like
children
aren't sufficiently described. For example,children
is most explicitly:
propTypes.oneOfType([
PropTypes.string,
PropTypes.null,
PropTypes.number,
PropTypes.node,
PropTypes.arrayOf(
propTypes.oneOfType([
PropTypes.string,
PropTypes.null,
PropTypes.number,
PropTypes.node,
])
)
])
- Use the
metadata.json
property types to raise helpful error messages. I used the Cerberus package recently for type-checking and I think it's a really good fit for this project. It has a declarative structure for describing nested properties that is very similar to the structure inmetadata.json
- Type validation will exist as part of the component base class: https://github.com/plotly/dash/blob/master/dash/development/base_component.py