Skip to content

Commit

Permalink
cancel drag on any uncaught errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreardon committed May 6, 2018
1 parent 0805272 commit 7ef1da9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/view/drag-drop-context/drag-drop-context.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,31 @@ export default class DragDropContext extends React.Component<Props> {
throw error;
}

onWindowError = (error: Error) => {
const state: State = this.store.getState();

if (state.phase === 'IDLE' || state.phase === 'DROP_COMPLETE') {
return;
}

if (process.env.NODE_ENV !== 'production') {
console.warn(`
An error has occurred withing a DragDropContext.
Any existing drag will be cancelled
`, error);
}

this.store.dispatch(clean());
}

componentDidMount() {
window.addEventListener('error', this.onWindowError);
this.styleMarshal.mount();
this.announcer.mount();
}

componentWillUnmount() {
window.addEventListener('error', this.onWindowError);
this.unsubscribe();
this.styleMarshal.unmount();
this.announcer.unmount();
Expand Down

0 comments on commit 7ef1da9

Please sign in to comment.