1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-16 04:04:06 +02:00

Don't attempt to remove event listeners from non-existent window (#1495)

```
<IFrameComponent>
  <SlateEditor {...props} />
</IFrameComponent>
```

Since react unmounts from top down, `IFrameComponent` will unmount first (destroying its window), then `SlateEditor` will unmount and attempt to access the iframe window (which no longer exists) throwing `Uncaught TypeError: Cannot read property 'document' of undefined`.

It should be safe to skip removing event listeners from windows that no longer exist since they will be garbage collected upon destruction of the window anyway
This commit is contained in:
Charlie Martin
2017-12-29 13:49:54 -05:00
committed by Ian Storm Taylor
parent 02c4837d4c
commit 29bcb1c8d6

View File

@@ -117,7 +117,9 @@ class Content extends React.Component {
componentWillUnmount() {
const window = getWindow(this.element)
window.document.removeEventListener('selectionchange', this.onNativeSelectionChange)
if (window) {
window.document.removeEventListener('selectionchange', this.onNativeSelectionChange)
}
// COMPAT: Restrict scope of `beforeinput` to mobile.
if ((IS_IOS || IS_ANDROID) && SUPPORTED_EVENTS.beforeinput) {