Skip to content

Commit

Permalink
Remove event listeners for Location on unmount
Browse files Browse the repository at this point in the history
Currently, if the component is not mounted (e.g. because on a different page),
the component will still receive the change event and the `onLocationChange`
callback changes its props via `this.props.setProps` with the itempath from
('_dashprivate_path') in the DOM. The object, however, is
not on the dom and a random other DOM element is assigned the changed props.

The PR deregisters the event listeners of the component is unmounted. They will
be added again via `componentDidMount` anyways if the component is mounted again.

fixes plotly#1346
  • Loading branch information
jowlo committed Mar 31, 2023
1 parent 0377ab6 commit 2f66df0
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ export default class Location extends Component {
this.updateLocation(this.props);
}

componentWillUnmount() {
window.onpopstate = () => {};
window.removeEventListener(
'_dashprivate_pushstate',
this.onLocationChange
);
}

UNSAFE_componentWillReceiveProps(nextProps) {
this.updateLocation(nextProps);
}
Expand Down

0 comments on commit 2f66df0

Please sign in to comment.