TypeError: Discourse._registerPluginCode is not a function

By pulling together some educated guessing, improved duck typing and a bit of monkey patching as @sam already might have suggested by his comment referenced above (thanks for the valuable hint!), we have been able to find the root cause and to provide a drop-in workaround.

Root cause

The root cause must be elsewhere, we just added an appropriate topic outlining our observations.

Workaround

When running this snippet in the Header phase (</head> will be too early!) of a theme component, it makes this error go away by monkey patching the ill-called _registerPluginCode method as a noop. The safeguards mentioned above will be able to do their jobs again and not croak on the browser console.

<!--
Work around `TypeError: Discourse._registerPluginCode is not a function`, see also:
- https://meta.discourse.org/t/typeerror-discourse-registerplugincode-is-not-a-function/88572
- https://meta.discourse.org/t/javascript-not-loading-on-certain-pages/92297
-->
<script language="javascript">
    if (!('Discourse' in window)) {
        window.Discourse = {};
    }
    if ('Discourse' in window && !('_registerPluginCode' in window.Discourse)) {
        // Make this a noop
        window.Discourse._registerPluginCode = function() {};
    }
</script>
1 Like