Having some issues with our plugin and Discourse's Ember API. Can anyone help?

The plugin puts an i-frame into Discourse and you can find it here

I keep it more or less updated to the latest version so the breaking change came recently. We’re currently running 3.3.0.beta1-dev.

In console i get 3 error messages which look like this:

docuss.js:225 Uncaught (in promise) ReferenceError: Ember is not defined
at docuss.js:225:1

Most probably this Ember object has been removed from the Discourse API in a recent version of Discourse, so this error comes after a Discourse upgrade effecting those objects.

Here’s all the fixes i made:

Change 1

assets\javascripts\discourse\initializers\docuss.js.es6
line 232

old:

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

new:

import { schedule } from '@ember/runloop'

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

Change 2

assets\javascripts\discourse\lib\DcsIFrame.js.es6
line 858

old:

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

new:

	import { schedule } from '@ember/runloop'

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

Change 3

assets\javascripts\discourse\lib\onDidTransition.js.es6
line 239

old:

const afterRender = res =>
  new Promise(resolve => {
    Ember.run.schedule('afterRender', null, () => resolve(res))

new:

import { schedule } from '@ember/runloop'

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

That cleared up all the error messages in console but created a series of new ones:

 Discourse v3.3.0.beta1-dev — https://github.com/discourse/discourse/commits/4c7d58a883 — Ember v5.5.0
app.js:197 Uncaught ReferenceError: Ember is not defined
    at s.callback (docuss.js:210:1)
    at s.exports (loader.js:106:1)
    at requireModule (loader.js:27:1)
    at y (app.js:171:18)
    at w (app.js:194:19)
    at app.js:157:29
    at e.start (app.js:51:5)
    at HTMLDocument.<anonymous> (start-app.js:5:7)
    at discourse-boot.js:20:12
    at discourse-boot.js:1:1

Here’s a live platform with the plugin turned on incase its helpful

Is that issue familiar to anyone ran into issues with Ember APIs objects changing. Any suggestions on how to fix them would be greatly appreciated.

2 Likes

Hello!

You forget this one:

I believe you could do something like that. This still should work.

import { observes } from "discourse-common/utils/decorators";

@observes("model.tags")
tagsChanged() {

}

On a side note, the composer controller has been moved to a service now.

4 Likes

Have you checked out the recommended alternative from the GitHub page?

The Author I believe is active here.

1 Like

Thanks for the suggestion @Heliosurge. We’ve baked the old one in pretty deep to our project though, so with the authors blessing we’ve taken over maintaining it.

A bit short on devs with the relevant skills in our Open Source community at the moment though.

1 Like

Yeah makes perfect sense.

1 Like

Thanks for that @Arkshine. My laptop died when a replacement charger fried the charging circuit, so i wasn’t able to test it out until i was able to repair the laptop yesterday.

I put the import statement at the top of the page and your code underneath but seem to be hitting syntax errors when i try to add that or similar variations of it:

Visual Basic Studio finds these errors:

// New tagsChanged function with @observes decorator
@observes("model.tags")
tagsChanged() {
  // See if it is a balloon tag

The open bracket at the end of this line: tagsChanged() {

has this error message:
‘;’ expected.ts(1005)

  1. The last bracket in the code also has an error flag with this message:

‘}’ expected.ts(1005)
docuss.js.es6(219, 54): The parser expected to find a ‘}’ to match the ‘{’ token here.

This is line 219:
tagsChanged: Ember.observer('model.tags', function() {

My server says this when i try to build:

  251 |     }, 0);
  252 |   }
> 253 | }.observes("model.tags"),
      |                          ^
        in /tmp/broccoli-6523ExbXtskE5c0h/out-1067-funnel
        at Babel (Babel: discourse-plugins)
  - name: Error
  - nodeAnnotation: Babel: discourse-plugins
  - nodeName: Babel
  - originalErrorMessage: /var/www/discourse/app/assets/javascripts/discourse/discourse/plugins/docuss/discourse/initializers/docuss.js: Unexpected token (253:25)