Skip to content

Validation on component properties #264

@chriddyp

Description

@chriddyp

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,
        ])
    )
])

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions