رابط الدردشة مفقود في أداة حدث المنشور بعد التجميع

مرحبًا :waving_hand:

واجهنا خطأً صغيرًا في ميزة الدردشة الخاصة بإضافة discourse-calendar، حيث اختفى رابط :speech_balloon: لقناة الدردشة فجأة من عنصر واجهة حدث المنشور.

على الأرجح، حدث هذا التعطل مع التغيير الأخير في نواة Discourse لنقل نظام البناء إلى Rollup:

  • af3385baba — تم إدخال مترجم Rollup (معطل افتراضيًا)
  • 74d532c559 — تم تمكين مترجم Rollup كإعداد افتراضي

يمكنني إصلاح المشكلة وتقديم طلب سحب (PR) لها :technologist: .

السلوك المتوقع

عند إضافة حدث إلى موضوع وتفعيل “دمج الدردشة” (“إنشاء وإدارة قناة دردشة خاصة بالحدث”)، يجب أن يتضمن عنصر واجهة الحدث في المنشور أيقونة :speech_balloon: مع رابط لقناة الدردشة المرتبطة بالحدث:

السلوك الحالي

في الوقت الحالي، على الفرع main الحالي، لا يتم عرض هذا القسم من عنصر واجهة حدث المنشور على الإطلاق:

الإصلاح/الحل

يبدو أن المشكلة تكمن في أن دالة optionalRequire الكسولة (lazy) لا تعمل كما هو مقصود في البداية مع Rollup. من فهمي، يقوم Rollup باستدعاء optionalRequire في وقت مبكر جدًا، عندما لم تُسجَّل الوحدات الأخرى بعد، وبالتالي فإنها تعيد دائمًا false.

ما يحل المشكلة هو نقل استدعاءات optionalRequire إلى منشئ الكائن (constructor) للمكون، بحيث يتم تقييمها فعليًا بشكل كسول.

على سبيل المثال، سيبدو الملف الخاص بالنموذج (model file) كالتالي:

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

(ملاحظة: أحتاج إلى تحويله إلى مكون من نوع فئة (class component)، ولهذا السبب يكون الاختلاف أكبر)

سأقدم طلب سحب (PR) مع إصلاحي على GitHub، حتى يتمكن الناس من تجربته والتعبير عن آرائهم حوله.

إعجابَين (2)

شكرًا لك @klappradla. يبدو لي أن الإصلاح المقترح جيد - يرجى نشر رابط لطلب السحب (PR) بمجرد استعداده :rocket:

ها هو → https://github.com/discourse/discourse/pull/39287

إعجاب واحد (1)