ElemeFE / ElemeFE/element-react
Select component with no options throws error when life cycle enters componentWillUnmount
- Dominant language
- JavaScript
- Stars
- 2.8k
- Forks
- 435
- PR merge metrics
- No merged PRs in 30d
Description
### Description
Select component with no select options throws error when calling `removeResizeListener` in `ComponentWillUnmount`.
I noticed that `addResizeListener(this.refs.root, this.resetInputWidth);` has been moved to `ComponentDidUpdate` in recent code commits(it was written in `componentDidMount` before). If users do nothing , `componentDidUpdate` will be never called, i.e. ` addResizeListener(this.refs.root, this.resetInputWidth);` will not be called, which results in throwing error if Select with empty children option components are unmounted.
Here are the new source codes:
Select.jsx
```
componentDidUpdate() {
this.state.inputWidth = this.reference.getBoundingClientRect().width;
addResizeListener(this.refs.root, this.resetInputWidth);
}
componentWillUnmount() {
removeResizeListener(this.refs.root, this.resetInputWidth);
}
```
### Solution
If select has no options, it is required to push an empty object into select options array, but I don't think it is the best practice for component usage
Contributor guide
Assessment
This issue has not been assessed yet.