ロールアップ後にポストイベントウィジェットからチャットリンクが欠落

こんにちは :waving_hand:

discourse-calendar プラグインのチャット機能で小さなバグが発生しました。ポストイベントウィジェット内のチャットチャンネルへの :speech_balloon: リンクが突然表示されなくなっています。

これは、Discourse コアでビルドシステムを Rollup に移行する最近の変更により、おそらく壊れたものです:

  • af3385baba — Rollup コンパイラの導入(デフォルトでは無効)
  • 74d532c559 — Rollup コンパイラをデフォルトで有効化

これを修正し、PR を提供することができます :technologist:

期待される動作

トピックにイベントを追加し、「チャット統合」(「イベント固有のチャットチャンネルを作成および管理」)を有効にすると、ポストのイベントウィジェットに、イベントに関連付けられたチャットチャンネルへのリンク付きの :speech_balloon: アイコンが含まれます:

現在の動作

現在、最新の main ブランチでは、ポストイベントウィジェット的这个セクションがまったくレンダリングされません:

修正/解決策

問題のようですのは、lazy optionalRequire ヘルパーが、Rollup を使用すると当初意図した通りに機能しなくなっていることです。私の理解では、Rollup は他のモジュールがまだ登録されていない段階で optionalRequire を呼び出してしまい、常に false を返してしまいます。

問題を解決するには、optionalRequire の呼び出しをコンポーネントのコンストラクタ内に移動し、実際に遅延評価されるようにすることです。

モデルファイルの場合、例えば次のようになります:

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;

また、実際のリンクをレンダリングするコンポーネントについても同様です:

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>
+}

(注:これをクラスコンポーネントに変換する必要があります。そのため、diff が大きくなっています)

GitHub で修正を含む PR を提供しますので、皆様にご試していただき、ご意見をお聞かせください。

「いいね!」 2

@klappradla さん、ありがとうございます。提案された修正は良さそうです。準備ができたら、PR のリンクを投稿してください :rocket:

こちらです → https://github.com/discourse/discourse/pull/39287

「いいね!」 1