Disable javascript for disabled plugins

One of the main issues people seem to have on Meta is broken plugins. There is a natural assumption that ‘disabling’ a plugin in the admin interface will stop any issues caused by it. The reality is that plugin javascript is still loaded, and can still completely break Discourse.

I have a working PR which ‘fixes’ this behaviour.

If you’ve ever looked at the plugin_third_party.js file, you’ll know it looks something like this (eval only used in development, but similar idea in production)

I’ve added a pre-processor which wraps those definitions so they end up like this:

Then, before the application starts up, discourse.js steps through each one of those definitions, and will ignore any definitions for disabled plugins. (we already have a list of disabled plugins client-side for automatically disabling plugin outlets).

https://github.com/davidtaylorhq/discourse/blob/disable-plugin-js/app/assets/javascripts/discourse.js.es6#L105-L113

As far as I can tell locally and on my instance, it works great. I can deliberately add a broken “import” line to a plugin file, see that the site is broken, go and disable the plugin, and then the site works again :tada:

Is this the right approach to be taking?

https://github.com/discourse/discourse/pull/5103

7 Likes

If one disables a plugin is there a way to force it to load so that it can be enebled?

The option to enable it is still available in the admin interface - that doesn’t need any JavaScript :slight_smile:

2 Likes