diff --git a/lib/KModal.vue b/lib/KModal.vue index dd8640720..fcf20f96d 100644 --- a/lib/KModal.vue +++ b/lib/KModal.vue @@ -291,23 +291,23 @@ this.$refs.modal.focus(); }, focusElementTest(event) { - // switching apps - not relevant - if (event.target === window) { + const { target } = event; + const noopOnFocus = + target === window || // switching apps + !this.$refs.modal || // if $refs.modal isn't available + target === this.$refs.modal || // addresses #3824 + this.$refs.modal.contains(target.activeElement); + if (noopOnFocus) { return; } - // not sure when this would be true - if (!this.$refs.modal) { - return; - } - // addresses https://github.com/learningequality/kolibri/issues/3824 - if ( - event.target === this.$refs.modal || - this.$refs.modal.contains(event.target.activeElement) - ) { + // Fixes possible infinite recursion when disconnection snackbars appear + // along with KModal (#6301) + const $coreSnackbar = document.getElementById('coresnackbar'); + if ($coreSnackbar && $coreSnackbar.contains(target)) { return; } // focus has escaped the modal - put it back! - if (!this.$refs.modal.contains(event.target)) { + if (!this.$refs.modal.contains(target)) { this.focusModal(); } },