Skip to content

Commit 36e403f

Browse files
committed
Enforced UNSAFE_componentWillReceiveProps on changed properties
1 parent 3d012e5 commit 36e403f

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

webapp/components/general/PythonControlledCapability.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,26 @@ define((require) => {
131131
}
132132

133133
UNSAFE_componentWillReceiveProps (nextProps) {
134-
this.disconnectFromPython();
135-
this.id = (nextProps.id === undefined) ? nextProps.model : nextProps.id;
136-
GEPPETTO.ComponentFactory.addExistingComponent(this.state.componentType, this);
137-
this.connectToPython(this.state.componentType, nextProps.model);
138-
if ((this.state.searchText !== nextProps.searchText) && (nextProps.searchText !== undefined)) {
139-
this.setState({ searchText: nextProps.searchText });
140-
}
141-
if ((this.state.checked !== nextProps.checked) && (nextProps.checked !== undefined)) {
142-
this.setState({ checked: nextProps.checked });
143-
}
144-
if ((this.state.value !== nextProps.value) && (nextProps.value !== undefined)) {
145-
this.setState({ value: nextProps.value });
146-
}
147-
if ((this.state.model !== nextProps.model) && (nextProps.model !== undefined)) {
148-
this.setState({ model: nextProps.model });
149-
}
134+
const matchingProps = JSON.stringify(this.props) == JSON.stringify(nextProps);
135+
if (!matchingProps)
136+
{
137+
this.disconnectFromPython();
138+
this.id = (nextProps.id === undefined) ? nextProps.model : nextProps.id;
139+
GEPPETTO.ComponentFactory.addExistingComponent(this.state.componentType, this);
140+
this.connectToPython(this.state.componentType, nextProps.model);
141+
if ((this.state.searchText !== nextProps.searchText) && (nextProps.searchText !== undefined)) {
142+
this.setState({ searchText: nextProps.searchText });
143+
}
144+
if ((this.state.checked !== nextProps.checked) && (nextProps.checked !== undefined)) {
145+
this.setState({ checked: nextProps.checked });
146+
}
147+
if ((this.state.value !== nextProps.value) && (nextProps.value !== undefined)) {
148+
this.setState({ value: nextProps.value });
149+
}
150+
if ((this.state.model !== nextProps.model) && (nextProps.model !== undefined)) {
151+
this.setState({ model: nextProps.model });
152+
}
153+
}
150154
}
151155

152156
componentDidUpdate (prevProps, prevState) {

0 commit comments

Comments
 (0)