Docuss bug. Ember is not Defined

I think this bug is because the ember package in Docuss needs to be updated. Slightly more complicated as there is no Ember package in Docuss. I think the Ember package is called server side by the rollups stated in rollup.config.js, so we need to find a way to update it in those or to override the ember.js package in out Github.

Docuss in our Github

Uncaught ReferenceError: jQuery is not defined
    at _discourse-events_extra-5d32b0f56319b2609ca863601bcd5873c4656008d0b46a28414ba5dec97bc13d.js:17:9
    at _discourse-events_extra-5d32b0f56319b2609ca863601bcd5873c4656008d0b46a28414ba5dec97bc13d.js:8:2
app.js:240 ℹ️ Discourse v3.3.0.beta1-dev — https://github.com/discourse/discourse/commits/e440996aca — Ember v5.5.0
deprecated.js:54 [PLUGIN discourse-events-e0079339aeef4bbe41336a3766e010483478c7374fcb7d7e0574c835848c6e01] Deprecation notice: [registerUnbound event-label] registerUnbound is deprecated. Instead, you should export a default function from 'discourse/helpers/event-label.js'. If the helper is also used in raw-hbs, you can register it using 'registerRawHelper'. [deprecation id: discourse.register-unbound]
l @ deprecated.js:54
Show 1 more frame
Show less
docuss.js:163 Uncaught (in promise) ReferenceError: Ember is not defined
    at Object.initialize (docuss.js:163:1)
    at n.initialize (app.js:208:28)
    at index.js:145:1
    at e.each (dag-map.js:191:1)
    at e.walk (dag-map.js:120:1)
    at e.each (dag-map.js:66:1)
    at e.topsort (dag-map.js:72:1)
    at e._runInitializer (index.js:158:1)
    at e.runInstanceInitializers (index.js:143:1)
    at u._bootSync (instance.js:86:1)
    at e.didBecomeReady (index.js:602:1)
    at invoke (backburner.js.js:280:1)
    at h.flush (backburner.js.js:197:1)
    at p.flush (backburner.js.js:358:1)
    at B._end (backburner.js.js:798:1)
    at B._boundAutorunEnd (backburner.js.js:523:1)
docuss.js:225 Uncaught (in promise) ReferenceError: Ember is not defined
    at docuss.js:225:1
    at new Promise (<anonymous>)
    at d (docuss.js:223:1)
    at Object.initialize (docuss.js:49:1)
    at n.initialize (app.js:208:28)
    at index.js:145:1
    at e.each (dag-map.js:191:1)
    at e.walk (dag-map.js:120:1)
    at e.each (dag-map.js:66:1)
    at e.topsort (dag-map.js:72:1)
    at e._runInitializer (index.js:158:1)
    at e.runInstanceInitializers (index.js:143:1)
    at u._bootSync (instance.js:86:1)
    at e.didBecomeReady (index.js:602:1)
    at invoke (backburner.js.js:280:1)
    at h.flush (backburner.js.js:197:1)
    at p.flush (backburner.js.js:358:1)
    at B._end (backburner.js.js:798:1)
    at B._boundAutorunEnd (backburner.js.js:523:1)

I had a quick look at this and I think the reason of this error is that:

  • You are using the dcs-discourse-plugin plugin;
  • In this plugin’s code, there are 3 references to an Ember object of the Discourse API (file docuss.js.es6, lines 168, 202, and 235);
  • Most probably this Ember object has been removed from the Discourse API in a recent version of Discourse, so you get this error after a Discourse upgrade.

If my analysis is correct, the solution is to clone dcs-discourse-plugin and fix the deprecated use of the Ember object. For example, the third occurrence of the Ember object is:

const afterRender = res =>
  new Promise(resolve => {
    // @ts-ignore
    Ember.run.schedule('afterRender', null, () => resolve(res))
  })

This can be replaced by:

import { schedule } from '@ember/runloop'

const afterRender = res =>
  new Promise(resolve => {
    schedule('afterRender', null, () => resolve(res))
  })

I don’t know about the two other occurrences.

1 Like

Thanks @syl. I have to apologise, i loaded up the wrong Git in Visual Studio. Your fix worked and led me to fix the other 2 easily.

Still not loading though. Hopefully you or someone from the @WebDev can review my code and see what i’m missing.

Here’s the code causing the error:

    ComposerController.reopen({
  composeStateChanged: Ember.observer('model.composeState', function() {
    // We are going to do something when the composer opens
    const state = this.get('model.composeState')
    if (state !== Composer.OPEN) {
      return
    }

Fix Effort:

ComposerController.reopen({
  composeStateChanged: function() {
    // We are going to do something when the composer opens
    const state = this.get('model.composeState');
    if (state !== this.constructor.OPEN) {
      return;
    }
  }.observes('model.composeState')
 });

Error Message:
docuss.js:184 Uncaught (in promise) TypeError: this.get is not a function
at Object.initialize (docuss.js:184:1)

That wasn’t one of the original messages so i think i’ve introduced it during my fix.

Here’s the file with the fix: dcs-discourse-plugin/assets/javascripts/discourse/initializers/docuss.js.es6 at master · focallocal/dcs-discourse-plugin · GitHub