Skip to content

A platform for community discussion. Free, open, simple.

DEV: Fix presence testing in legacy ember environment (#14596)

David Taylorbc68da24cd87
diff --git a/app/assets/javascripts/discourse/app/services/presence.js b/app/assets/javascripts/discourse/app/services/presence.js
index 85ae22b5ece..ac1ba6d3af3 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