From c0179a56f8793012ddfa313e64001accccacaa6f Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 18 Jan 2023 14:39:57 +0100 Subject: [PATCH] FIX: ensures chat is present/enabled (#68) Without this when chat is disabled the API is not supercharged with these methods and it will cause an exception: ``` Uncaught (in promise) TypeError: t.decorateChatMessage is not a function initialize discourse-math-mathjax.js:102 initialize discourse-math-mathjax.js:119 withPluginApi discourse-f7231bd5d10aa613b323a0cac71d8003baa74ef74f674fe4f91e4857994e661b.br.js:4735 initialize discourse-math-mathjax.js:118 initialize discourse-f7231bd5d10aa613b323a0cac71d8003baa74ef74f674fe4f91e4857994e661b.br.js:67 runInstanceInitializers Ember each dag-map.js:192 walk dag-map.js:121 each dag-map.js:66 topsort dag-map.js:72 Ember 4 invoke queue.ts:201 flush queue.ts:98 flush deferred-action-queues.ts:75 _end index.ts:616 _boundAutorunEnd index.ts:257 discourse-math-mathjax.js:102 ``` --- .../initializers/discourse-math-mathjax.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/assets/javascripts/initializers/discourse-math-mathjax.js b/assets/javascripts/initializers/discourse-math-mathjax.js index a6be5ae..f0e96a4 100644 --- a/assets/javascripts/initializers/discourse-math-mathjax.js +++ b/assets/javascripts/initializers/discourse-math-mathjax.js @@ -116,14 +116,16 @@ function initializeMath(api, discourseMathOptions) { { id: "mathjax" } ); - api.decorateChatMessage( - (element) => { - mathjax(element, discourseMathOptions); - }, - { - id: "mathjax-chat", - } - ); + if (api.decorateChatMessage) { + api.decorateChatMessage( + (element) => { + mathjax(element, discourseMathOptions); + }, + { + id: "mathjax-chat", + } + ); + } } export default {