Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit 755d752

Browse files
Re-render on changes to undefined props (#785)
1 parent bee4a4f commit 755d752

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1111
- Clicking on a link in a Markdown cell now requires a single click instead of two
1212
- Links in Markdown cells now open a new tab (target="_blank")
1313

14+
### Fixed
15+
- [#785](https://github.com/plotly/dash-table/pull/785) Fix a bug where the table does not refresh correctly if a property was previously missing
16+
1417
## [4.7.0] - 2020-05-05
1518
### Added
1619
- [#729](https://github.com/plotly/dash-table/pull/729) Improve conditional styling

src/dash-table/components/Table/index.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ import 'react-select/dist/react-select.css';
2020
import './Table.less';
2121
import './style';
2222
import './Dropdown.css';
23-
import { isEqual } from 'core/comparer';
2423
import { SingleColumnSyntaxTree } from 'dash-table/syntax-tree';
2524
import derivedFilterMap from 'dash-table/derived/filter/map';
2625

2726
import controlledPropsHelper from './controlledPropsHelper';
2827
import derivedPropsHelper from './derivedPropsHelper';
2928
import DOM from 'core/browser/DOM';
30-
31-
const DERIVED_REGEX = /^derived_/;
29+
import shouldComponentUpdate from './shouldComponentUpdate';
3230

3331
export default class Table extends Component<SanitizedAndDerivedProps, StandaloneState> {
3432
constructor(props: SanitizedAndDerivedProps) {
@@ -94,10 +92,7 @@ export default class Table extends Component<SanitizedAndDerivedProps, Standalon
9492
const props: any = this.props;
9593
const state: any = this.state;
9694

97-
return R.any(key =>
98-
!DERIVED_REGEX.test(key) && props[key] !== nextProps[key],
99-
R.keysIn(props)
100-
) || !isEqual(state, nextState);
95+
return shouldComponentUpdate(props, nextProps, state, nextState);
10196
}
10297

10398
render() {
@@ -159,3 +154,4 @@ export default class Table extends Component<SanitizedAndDerivedProps, Standalon
159154
private readonly controlledPropsHelper = controlledPropsHelper();
160155
private readonly updateDerivedProps = derivedPropsHelper();
161156
}
157+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as R from 'ramda';
2+
import { isEqual } from 'core/comparer';
3+
4+
const DERIVED_REGEX = /^derived_/;
5+
6+
export default (
7+
props: any,
8+
nextProps: any,
9+
state: any,
10+
nextState: any
11+
) => R.any(
12+
key => !DERIVED_REGEX.test(key) && props[key] !== nextProps[key],
13+
R.keysIn({ ...props, ...nextProps })
14+
) || !isEqual(state, nextState);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import shouldComponentUpdate from 'dash-table/components/Table/shouldComponentUpdate';
2+
3+
describe('shouldComponentUpdate', () => {
4+
it('should update on undefined -> defined props', () => {
5+
assert(shouldComponentUpdate({}, { a: 0 }, {}, {}));
6+
});
7+
8+
it('should update on undefined -> defined state', () => {
9+
assert(shouldComponentUpdate({}, {}, {}, { a: 0 }));
10+
});
11+
12+
it('should update on defined -> undefined props', () => {
13+
assert(shouldComponentUpdate({ a: 0 }, {}, {}, {}));
14+
});
15+
16+
it('should update on defined -> undefined state', () => {
17+
assert(shouldComponentUpdate({}, {}, { a: 0 }, {}));
18+
});
19+
20+
it('should not update on derived props', () => {
21+
assert(!shouldComponentUpdate({ derived_test: 0 }, { derived_test: 1 }, {}, {}));
22+
});
23+
24+
it('should update on derived state', () => {
25+
assert(shouldComponentUpdate({}, {}, { derived_test: 0 }, { derived_test: 1 }));
26+
});
27+
});

tests/integration/review_app/test_app_df_graph.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,8 @@ def update_graph(rows, selected_rows):
152152
dash_duo.wait_for_element("#waitfor")
153153

154154
dash_duo.wait_for_element("#{}".format(IDS["table"]))
155+
dash_duo.wait_for_element("#pop svg")
156+
dash_duo.wait_for_element("#lifeExp svg")
157+
dash_duo.wait_for_element("#gdpPercap svg")
155158

156159
dash_duo.percy_snapshot("rapp002 - loaded")

0 commit comments

Comments
 (0)