This is unexpected, especially since I’m not actually “changing anything” (yet)?
I’m able to reproduce this problem even if this is the only modification.
Ultimately the reason I’m trying to change this is so that I can force a re-evaluation of this template even if I’m not moving in or out of a topic route.
Ultimately I want to add logic so that the widget is forced to refresh when moving in and out of category routes because my Category route presentation needs to be different.
So one solution to this might be another way to force the header contents to be refreshed.
In any case, this doesn’t seem to be behaving as I should expect?
We don’t really want to invest much time here - widgets aren’t going to be around for much longer. What customization are you trying to make? Can we help by adding a plugin outlet somewhere (we have the ability to add normal plugin outlets inside widget code now).
Can you share more of your file (e.g. where is hbs being imported from?)
Functionally I’m trying to swap the logo depending on the route. In reality I’m doing this by attaching an image to the home logo on some routes and overlaying the primary logo. I want that logic to be re-evaluated when moving between routes, which currently seems to work moving in and out of the Topic routes I’m guessing because the header-contents widget to which everything is attached has logic evaluating the attrs.topic which obviously changes when that occurs.
Which works fine, but is not being re-evaluated between certain route transitions, so isn’t fulfilling the requirement fully dynamically without a page reload.
oooooops, this could be the issue, I had a feeling it might be but my tests were obviously too superficial to rule this out.
This is likely the problem. Widget ‘templates’ are a custom Discourse thing, and are compiled in a totally different way to Ember templates. You’ll need to import hbs like this:
Looks like we have a site-header:force-refresh appEvent which you could trigger in response to some other appEvent or Ember router event:
btw, just as a side note here, whilst the widget API is all very bespoke and somewhat fiddly (especially the hyperscript stuff), I must admit it is extremely powerful to attach new behaviour to existing widgets without having to override lots of code.
for example I’ve used this pattern a lot:
api.reopenWidget('discourse-awesome-widget', {
html(attrs, state) {
let contents = this._super(...arguments);
contents.unshift(h("div.my-cool-new-thing", "cool new thing"))
return contents;
}
});
this._super could be a lot of code!!!
And it can get a lot cleverer than that such that I’ve come to really appreciate it.
I hope the “override-abiliy” of whatever replaces it will be as equally flexible and powerful.