Hi ![]()
we ran into a small bug with the chat feature of the discourse-calendar plugin, where the
-link to the chat channel was suddenly missing in the post event widget.
It most likely broke with the recent change in Discourse core to move the build system to Rollup:
- af3385baba โ Introduced the Rollup compiler (disabled by default)
- 74d532c559 โ Enabled the Rollup compiler as default
I can fix it and provide a PR for it
.
Expected behavior
When adding an event to a topic and enabling the Chat Integration ("Create and manage event specific chat channel"), the event widget on the post would include a
-icon with a link to the chat channel associated with the event:
Current behavior
At the moment, on current main, this section of the post event widget is just not rendered at all:
Fix/Solution
The issue seems to be, that the lazy optionalRequire helper does not work as initially intended any more with Rollup. From my understanding, Rollup calls the optionalRequire too early, when other modules arenโt yet registered and so it always returns false.
What fixes the problem, is to move the optionalRequire calls into the componentโs constructor, so that itโs actually evaluated lazily.
For the model file, it would for instance look like this:
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/models/discourse-post-event-event.js b/plugins/discourse-calendar/assets/javascripts/discourse/models/discourse-post-event-event.js
index 742cc35a84..f687b956aa 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/models/discourse-post-event-event.js
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/models/discourse-post-event-event.js
@@ -7,10 +7,6 @@ import User from "discourse/models/user";
import DiscoursePostEventEventStats from "./discourse-post-event-event-stats";
import DiscoursePostEventInvitee from "./discourse-post-event-invitee";
-const ChatChannel = optionalRequire(
- "discourse/plugins/chat/discourse/models/chat-channel"
-);
-
const DEFAULT_REMINDER = {
type: "notification",
value: 15,
@@ -62,6 +58,8 @@ export default class DiscoursePostEventEvent {
@tracked _reminders;
constructor(args = {}) {
+ const ChatChannel = optionalRequire( "discourse/plugins/chat/discourse/models/chat-channel");
+
this.id = args.id;
this.rrule = args.rrule;
this.name = args.name;
And respectively for the component that renders the actual link:
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/chat-channel.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/chat-channel.gjs
index f673ee8a9f..a988b341e6 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/chat-channel.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/discourse-post-event/chat-channel.gjs
@@ -1,24 +1,27 @@
+import Component from "@glimmer/component";
import { LinkTo } from "@ember/routing";
import { optionalRequire } from "discourse/lib/utilities";
import { and } from "discourse/truth-helpers";
-const ChannelTitle = optionalRequire(
- "discourse/plugins/chat/discourse/components/channel-title"
-);
+export default class DiscoursePostEventChatChannel extends Component {
+ get channelTitle() {
+ return optionalRequire(
+ "discourse/plugins/chat/discourse/components/channel-title"
+ );
+ }
-const DiscoursePostEventChatChannel = <template>
- {{#if (and @event.channel ChannelTitle)}}
- <section class="event__section event-chat-channel">
- <span></span>
- <LinkTo
- @route="chat.channel"
- @models={{@event.channel.routeModels}}
- class="chat-channel-link"
- >
- <ChannelTitle @channel={{@event.channel}} />
- </LinkTo>
- </section>
- {{/if}}
-</template>;
-
-export default DiscoursePostEventChatChannel;
+ <template>
+ {{#if (and @event.channel this.channelTitle)}}
+ <section class="event__section event-chat-channel">
+ <span></span>
+ <LinkTo
+ @route="chat.channel"
+ @models={{@event.channel.routeModels}}
+ class="chat-channel-link"
+ >
+ <this.channelTitle @channel={{@event.channel}} />
+ </LinkTo>
+ </section>
+ {{/if}}
+ </template>
+}
(Note: I need to convert it to a class component, thatโs why the diff is bigger)
I will provide a PR with my fix on GitHub, so people can try it out and voice there opinions about it.

