Skip to content

Commit

Permalink
fix(grid): let the thing update, do prop changes in the sane place
Browse files Browse the repository at this point in the history
also destroy the grid on unmount to remove hanging refs
  • Loading branch information
scamden committed Aug 12, 2021
1 parent 87de2bf commit 4ebe677
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 35 deletions.
108 changes: 89 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"classnames": "^2.2.5",
"grid": "^4.10.8",
"grid": "~4.10.9",
"lodash": "^4.17.4",
"react": "^16.0.0",
"react-dom": "^16.0.0"
Expand Down
32 changes: 17 additions & 15 deletions src/lib/components/grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,6 @@ export class ReactGrid extends Component<IGridProps, IGridState> {
}
}

shouldComponentUpdate(nextProps: IGridProps) {
if (this.descriptorsChanged(this.props.rows, nextProps.rows)) {
this.reflectNewRowsOrCols(nextProps.rows, this.grid.rows);
}
if (this.descriptorsChanged(this.props.cols, nextProps.cols)) {
this.reflectNewRowsOrCols(nextProps.cols, this.grid.cols);
}

if (this.props.data !== nextProps.data) {
this.handleNewData(nextProps.data);
}
return false;
}

componentDidMount() {
this.ensureGridContainerInDOM();
this.grid.build(this.gridContainer);
Expand Down Expand Up @@ -180,8 +166,24 @@ export class ReactGrid extends Component<IGridProps, IGridState> {
}

// we return false from should update but react may ignore our hint in the future
componentDidUpdate() {
componentDidUpdate(prevProps : IGridProps) {
this.ensureGridContainerInDOM();

const nextProps = this.props;
if (this.descriptorsChanged(prevProps.rows, nextProps.rows)) {
this.reflectNewRowsOrCols(nextProps.rows, this.grid.rows);
}
if (this.descriptorsChanged(prevProps.cols, nextProps.cols)) {
this.reflectNewRowsOrCols(nextProps.cols, this.grid.cols);
}

if (prevProps.data !== nextProps.data) {
this.handleNewData(nextProps.data);
}
}

componentWillUnmount(){
this.grid.destroy();
}

render() {
Expand Down

0 comments on commit 4ebe677

Please sign in to comment.