Discourse._registerPluginCode should never run code before objects are injected


(Sam Saffron) #1

Currently themes transpile code in <script type="text/discourse-plugin" version="0.8"> to: Discourse._registerPluginCode('0.8', function (api)

This call often can happen before the application has initialized and thus api.getCurrentUser can be null if this is registered too early (eg in header).

We should change it so registerPluginCode always runs after all objects are injected into the context so the api is fully functional.


(Robin Ward) #3

I can’t seem to reproduce this. I added the following code to the header:

<script type="text/discourse-plugin" version="0.8">
  console.log(api.getCurrentUser());
</script>

When I reload the page it outputs my user model. How can I reproduce this?


(Robin Ward) #4

Okay it looks like a lot of plugins were not executing after inject-objects which was caching null. This fixes it:


(Robin Ward) #5