From 0829da53b099bb1c9625b4086134fbbb0d6a0f79 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 16 Dec 2014 14:36:51 -0800 Subject: [PATCH] Properly unmount the component when the shadow DOM is enabled. --- spec/text-editor-element-spec.coffee | 25 +++++++++++++++++++++++++ src/text-editor-element.coffee | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/spec/text-editor-element-spec.coffee b/spec/text-editor-element-spec.coffee index b5f05f4d9..5a813a8cd 100644 --- a/spec/text-editor-element-spec.coffee +++ b/spec/text-editor-element-spec.coffee @@ -32,6 +32,31 @@ describe "TextEditorElement", -> element.setModel(model) expect(element.hasAttribute('mini')).toBe true + describe "when the editor is attached to the DOM", -> + describe "when the editor.useShadowDOM config option is true", -> + it "mounts the react component and unmounts when removed from the dom", -> + atom.config.set('editor.useShadowDOM', true) + + element = new TextEditorElement + jasmine.attachToDOM(element) + + component = element.component + expect(component.isMounted()).toBe true + element.getModel().destroy() + expect(component.isMounted()).toBe false + + describe "when the editor.useShadowDOM config option is false", -> + it "mounts the react component and unmounts when removed from the dom", -> + atom.config.set('editor.useShadowDOM', false) + + element = new TextEditorElement + jasmine.attachToDOM(element) + + component = element.component + expect(component.isMounted()).toBe true + element.getModel().destroy() + expect(component.isMounted()).toBe false + describe "focus and blur handling", -> describe "when the editor.useShadowDOM config option is true", -> it "proxies focus/blur events to/from the hidden input inside the shadow root", -> diff --git a/src/text-editor-element.coffee b/src/text-editor-element.coffee index 47fc3f67a..b101fafb5 100644 --- a/src/text-editor-element.coffee +++ b/src/text-editor-element.coffee @@ -123,7 +123,7 @@ class TextEditorElement extends HTMLElement unmountComponent: -> return unless @component?.isMounted() callRemoveHooks(this) - React.unmountComponentAtNode(this) + React.unmountComponentAtNode(@rootElement) @component = null focused: ->