From 35656a1d5fe86f4aa14a60a44de2c0d1f6a41215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 9 Dec 2024 18:01:22 +0100 Subject: [PATCH] DEV: attempt to fix some system spec flakes (#30182) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since 3e7f0867ea044ffd3e957946e1996736d4a19df8, I started seeing some specs fail due to the following error ```plain Error occurred while rendering: top-level application > discourse-root > topic > discourse-topic > topic-navigation > plugin-outlet > plugin-connector > topic-presence-display /assets/plugins/discourse-presence.js - Uncaught TypeError: Cannot destructure property 'whisperer' of 'this.currentUser' as it is null. ``` For some reasons I can't fanthom, the presence components seem to be rendered even though they're using outlets that are only rendered when a user is signed in... 🤷‍♂️ Lost too much time trying to reproduce so I ended up adding this `if (!this.currentUser) { return; }` condition to both "presence display" component to (hopefully) fix these flakes. --- .../discourse/components/composer-presence-display.gjs | 6 ++++++ .../discourse/components/topic-presence-display.gjs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/plugins/discourse-presence/assets/javascripts/discourse/components/composer-presence-display.gjs b/plugins/discourse-presence/assets/javascripts/discourse/components/composer-presence-display.gjs index 7da31830ce8..e975510342b 100644 --- a/plugins/discourse-presence/assets/javascripts/discourse/components/composer-presence-display.gjs +++ b/plugins/discourse-presence/assets/javascripts/discourse/components/composer-presence-display.gjs @@ -33,6 +33,12 @@ export default class ComposerPresenceDisplay extends Component { }); setupWhisperChannel = helperFn((_, on) => { + // NOTE: this is here to prevent some flakes in tests + // For some random reasons, this component is being rendered even though `currentUser` is `null` + if (!this.currentUser) { + return; + } + const { topic } = this.args.model; const { whisperer } = this.currentUser; diff --git a/plugins/discourse-presence/assets/javascripts/discourse/components/topic-presence-display.gjs b/plugins/discourse-presence/assets/javascripts/discourse/components/topic-presence-display.gjs index e85890bb6bf..5df9df8beb3 100644 --- a/plugins/discourse-presence/assets/javascripts/discourse/components/topic-presence-display.gjs +++ b/plugins/discourse-presence/assets/javascripts/discourse/components/topic-presence-display.gjs @@ -30,6 +30,12 @@ export default class TopicPresenceDisplay extends Component { }); setupWhisperChannel = helperFn((_, on) => { + // NOTE: this is here to prevent some flakes in tests + // For some random reasons, this component is being rendered even though `currentUser` is `null` + if (!this.currentUser) { + return; + } + const { topic } = this.args; const { whisperer } = this.currentUser;