From d3422786c37f72e8576dce09fed21ad405c271c2 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 3 Sep 2014 10:53:41 -0600 Subject: [PATCH] Unmount component when EditorView is detached MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #3431 When a pane item is moved to another pane, we *detach* the associated view but we don’t fully remove it. This was to prevent removing a view when it was used as the pane item directly. However, this was causing the editor component not to be unmounted, which caused leaks and incorrect measurements. We need to unmount the component, but we don’t want to destroy the editor. So I’ve moved editor destruction to the wrapper view for now, and I only do it when the view is actually removed. Ultimately, we need to have a 1:1 relationship with pane items and their views and only allow a pane item to appear once in the pane tree. Then we can recycle the same view and avoid this confusing situation where the old view is detached and a new view is created. --- src/editor-component.coffee | 5 +++-- src/editor-view.coffee | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/editor-component.coffee b/src/editor-component.coffee index d72fccbf7..870a984fa 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -183,12 +183,13 @@ EditorComponent = React.createClass @checkForVisibilityChange() componentWillUnmount: -> - @props.parentView.trigger 'editor:will-be-removed', [@props.parentView] + {editor, parentView} = @props + + parentView.trigger 'editor:will-be-removed', [parentView] @unsubscribe() window.removeEventListener 'resize', @requestHeightAndWidthMeasurement clearInterval(@domPollingIntervalId) @domPollingIntervalId = null - @props.editor.destroy() componentWillReceiveProps: (newProps) -> @props.editor.setMini(newProps.mini) diff --git a/src/editor-view.coffee b/src/editor-view.coffee index cc18f7e9e..2f945f458 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -215,12 +215,22 @@ class EditorView extends View view.css('z-index', 1) @find('.lines').prepend(view) + detach: -> + return unless @attached + super + @attached = false + @unmountComponent() + beforeRemove: -> return unless @attached @attached = false - React.unmountComponentAtNode(@element) if @component.isMounted() + @unmountComponent() + @editor.destroy() @trigger 'editor:detached', this + unmountComponent: -> + React.unmountComponentAtNode(@element) if @component.isMounted() + # Public: Split the editor view left. splitLeft: -> pane = @getPane()