I think this may be a bug in Discourse, but am not sure. Maybe I am doing something wrong.
I have a plugin which adds information to the user-card-post-names
connector.
Handlebars:
Javascript:
That in turn calls this Javascript which does most of the work:
Problem details:
Within the previous JS code are these two lines:
var version = userModel.custom_fields && userModel.custom_fields["directoryopus_link_version"];
var edition = userModel.custom_fields && userModel.custom_fields["directoryopus_link_edition"];
It then does a test if (version || edition) { ...
and generates some strings (opusLinkClass
, opusLinkIcon
, opusLinkText
) depending on the result, which it then stores:
component.set("opusLinkClass", opusLinkClass);
component.set("opusLinkIcon", opusLinkIcon);
component.set("opusLinkText", opusLinkText);
Those strings are then used in the handlebars file at the start of this post.
There are never any errors or warnings in the browser’s log window, but sometimes this goes wrong.
I am testing with an account which has both custom_fields set, so the if (version || edition)
test should always go down the first branch, not the else if (!viewingStaff)
below it.
Yet sometimes it goes down the second branch, meaning version
and edition
weren’t set.
This doesn’t usually happen, which is why I think it may be a bug in Discourse.
It seems to only go wrong if I create a new thread and then reply to it, or if I edit a reply I just made. It’s like the userModel object isn’t initialised properly when the connector is run in some situations, maybe due to a race condition somewhere?
It seems to only goes wrong once per thread. If I F5 refresh the page, everything is fine again, and continues to be fine for that thread. (At least as far as I can tell. It seems semi-random, so it’s possible I just haven’t seen it happen again for the same thread.)
Thanks for your time and any suggestions.