From bc68da24cd878dbd760f6a121c6899ae6a288f85 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 13 Oct 2021 17:24:19 +0100 Subject: [PATCH] DEV: Fix presence testing in legacy ember environment (#14596) The legacy testing environment will remove the User.current() value before disposing of controllers/components. Presence often involves making HTTP calls during disposal of components, so this can cause issues. Production, and the modern Ember-CLI environment, do not require this hack, so it is behind an `isTesting() && isLegacyEmber()` check. --- .../javascripts/discourse/app/services/presence.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/app/services/presence.js b/app/assets/javascripts/discourse/app/services/presence.js index 85ae22b5ec..ac1ba6d3af 100644 --- a/app/assets/javascripts/discourse/app/services/presence.js +++ b/app/assets/javascripts/discourse/app/services/presence.js @@ -5,7 +5,7 @@ import { ajax } from "discourse/lib/ajax"; import { cancel, debounce, later, next, once, throttle } from "@ember/runloop"; import Session from "discourse/models/session"; import { Promise } from "rsvp"; -import { isTesting } from "discourse-common/config/environment"; +import { isLegacyEmber, isTesting } from "discourse-common/config/environment"; import User from "discourse/models/user"; const PRESENCE_INTERVAL_S = 30; @@ -464,8 +464,14 @@ export default class PresenceService extends Service { } }); } catch (e) { - // Updating server failed. Put the failed events - // back in the queue for next time + if (e.jqXHR?.status === 403 && isTesting() && isLegacyEmber()) { + // Legacy testing environment will remove the User.current() value before disposing of controllers/components. + // Presence often involves making HTTP calls during disposal of components, so this can cause issues. + // Modern Ember-CLI environment does not require this hack + return; + } + + // Put the failed events back in the queue for next time this._queuedEvents.unshift(...queue); if (e.jqXHR?.status === 429) { // Rate limited. No need to raise, we'll try again later