Adding pluginId to modifyClass when a mixin is used

I am trying to squash the warning:

[PLUGIN discourse-layouts] To prevent errors in tests, add a `pluginId` key to your `modifyClass` call. This will ensure the modification is only applied once.

However, in the case of the Layouts plugin, there is a Mixin called Sidebars being passed in to the api.modifyClass() method like so:

api.modifyClass(controllerClass, Sidebars) (See code)

I’ve tried many things, including adding the pluginId to a property on the Mixin:

export default Mixin.create({
  pluginId: 'discourse-layouts',
  router: service(),
  path: alias("router._router.currentPath"),
...

However the warning continues to appear.

The only way I was able to suppress the warning was by using this code instead of modifyClass()

 const klass = api._resolveClass(controllerClass, {});
 klass.class.reopen(Sidebars);

However, I don’t feel its the best approach because I’m essentially skipping the check that helps prevent modifyClass from being applied over and over.

Does anybody have any advice or thoughts on how I can add the pluginId to api.modifyClass() when a mixin is used and successfully supress that warning?

5 Likes