Skip to content

Commit

Permalink
Allow destroying an editor when it failed to render properly
Browse files Browse the repository at this point in the history
If the editor throws an error while rendering an atom, later calling
`editor.destroy` can create issues. This ensures that the editor-dom
renderer doesn't choke when destroying an atom renderNode if it didn't
properly render.
  • Loading branch information
bantic committed Apr 19, 2016
1 parent 242a4f5 commit e16e0d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/js/renderers/editor-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ let destroyHooks = {
// FIXME before we render marker, should delete previous renderNode's element
// and up until the next marker element

// If an atom throws during render we may end up later destroying a renderNode
// that has not rendered yet, so exit early here if so.
if (!renderNode.isRendered) {
return;
}
let { markupElement } = renderNode;

if (marker.section) {
Expand Down
6 changes: 1 addition & 5 deletions tests/unit/editor/atom-lifecycle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ module('Unit: Editor: Atom Lifecycle', {
},
afterEach() {
if (editor) {
try {
editor.destroy();
} catch(e) {}
editor.destroy();
editor = null;
}
}
Expand Down Expand Up @@ -207,8 +205,6 @@ test('rendering unknown atom without unknownAtomHandler throws', (assert) => {
}, new RegExp(`Unknown atom "${atomName}".*no unknownAtomHandler`));
});



test('onTeardown hook is called when editor is destroyed', (assert) => {
const atomName = 'test-atom';

Expand Down

0 comments on commit e16e0d6

Please sign in to comment.