diff --git a/src/converse-chatboxviews.js b/src/converse-chatboxviews.js index ae3728e6b..0b63590bb 100644 --- a/src/converse-chatboxviews.js +++ b/src/converse-chatboxviews.js @@ -71,7 +71,9 @@ converse.plugins.add('converse-chatboxviews', { /* Override method from backbone.js * If the #conversejs element doesn't exist, create it. */ - if (!this.el) { + if (this.el) { + this.setElement(result(this, 'el'), false); + } else { let el = _converse.root.querySelector('#conversejs'); if (el === null) { el = document.createElement('div'); @@ -85,10 +87,7 @@ converse.plugins.add('converse-chatboxviews', { _converse.root.appendChild(el); } } - el.innerHTML = ''; this.setElement(el, false); - } else { - this.setElement(result(this, 'el'), false); } }, @@ -108,19 +107,17 @@ converse.plugins.add('converse-chatboxviews', { }, render () { - try { - render(tpl_converse(), this.el); - } catch (e) { - this._ensureElement(); - render(tpl_converse(), this.el); - } + this._ensureElement(); + render(tpl_converse(), this.el); this.row_el = this.el.querySelector('.row'); }, + /*( + * Add a new DOM element (likely a chat box) into the + * the row managed by this overview. + * @param { HTMLElement } el + */ insertRowColumn (el) { - /* Add a new DOM element (likely a chat box) into the - * the row managed by this overview. - */ this.row_el.insertAdjacentElement('afterBegin', el); }, @@ -135,10 +132,7 @@ converse.plugins.add('converse-chatboxviews', { /************************ BEGIN Event Handlers ************************/ - api.listen.on('cleanup', () => { - _converse?.chatboxviews.remove(); - delete _converse.chatboxviews; - }); + api.listen.on('cleanup', () => (delete _converse.chatboxviews)); api.listen.on('chatBoxesInitialized', () => { _converse.chatboxviews = new _converse.ChatBoxViews({ diff --git a/src/headless/converse-core.js b/src/headless/converse-core.js index 6f1853e20..30c602bc4 100644 --- a/src/headless/converse-core.js +++ b/src/headless/converse-core.js @@ -424,6 +424,9 @@ export const api = _converse.api = { * event handlers' promises have been resolved. */ async trigger (name) { + if (!_converse._events) { + return; + } const args = Array.from(arguments); const options = args.pop(); if (options && options.synchronous) { @@ -1310,7 +1313,7 @@ async function getLoginCredentialsFromBrowser () { // Make sure everything is reset in case this is a subsequent call to // converse.initialize (happens during tests). async function cleanup () { - await _converse.api.trigger('cleanup', {'synchronous': true}); + await api.trigger('cleanup', {'synchronous': true}); _converse.router.history.stop(); unregisterGlobalEventHandlers(); _converse.connection?.reset();