From 7ef1da9da843a3903d8d1c389f6c61f02b2b7f0e Mon Sep 17 00:00:00 2001 From: Alex Reardon Date: Sun, 6 May 2018 21:22:31 +1000 Subject: [PATCH] cancel drag on any uncaught errors --- .../drag-drop-context/drag-drop-context.jsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/view/drag-drop-context/drag-drop-context.jsx b/src/view/drag-drop-context/drag-drop-context.jsx index 02fc8b17cb..dde20f5d63 100644 --- a/src/view/drag-drop-context/drag-drop-context.jsx +++ b/src/view/drag-drop-context/drag-drop-context.jsx @@ -213,12 +213,31 @@ export default class DragDropContext extends React.Component { 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();