A platform for community discussion. Free, open, simple.
DEV: Don't nest deferring calls (#30449)
Jarek Radosz184ec95d01a7
diff --git a/app/assets/javascripts/discourse/app/components/composer-editor.js b/app/assets/javascripts/discourse/app/components/composer-editor.jsindex 5865d89ff66..8e76b30d93e 100644--- a/app/assets/javascripts/discourse/app/components/composer-editor.js+++ b/app/assets/javascripts/discourse/app/components/composer-editor.js@@ -1,7 +1,7 @@import Component from "@ember/component";import EmberObject, { action, computed } from "@ember/object";import { getOwner } from "@ember/owner";-import { next, schedule, throttle } from "@ember/runloop";+import { schedule, throttle } from "@ember/runloop";import { service } from "@ember/service";import { classNameBindings } from "@ember-decorators/component";import { observes, on } from "@ember-decorators/object";@@ -803,13 +803,11 @@ export default class ComposerEditor extends Component {this.appEvents.trigger(`${this.composerEventPrefix}:will-close`);- next(() => {- // need to wait a bit for the "slide down" transition of the composer- discourseLater(- () => this.appEvents.trigger(`${this.composerEventPrefix}:closed`),- 400- );- });+ // need to wait a bit for the "slide down" transition of the composer+ discourseLater(+ () => this.appEvents.trigger(`${this.composerEventPrefix}:closed`),+ 400+ );preview?.removeEventListener("click", this._handleAltTextCancelButtonClick);preview?.removeEventListener("click", this._handleAltTextEditButtonClick);diff --git a/app/assets/javascripts/discourse/app/services/route-scroll-manager.js b/app/assets/javascripts/discourse/app/services/route-scroll-manager.jsindex a615f600cd3..d121d3058a3 100644--- a/app/assets/javascripts/discourse/app/services/route-scroll-manager.js+++ b/app/assets/javascripts/discourse/app/services/route-scroll-manager.js@@ -1,4 +1,4 @@-import { next, schedule } from "@ember/runloop";+import { next } from "@ember/runloop";import Service, { service } from "@ember/service";import { bind } from "discourse/lib/decorators";import { isTesting } from "discourse/lib/environment";@@ -55,11 +55,7 @@ export default class RouteScrollManager extends Service {const scrollLocation = this.historyStore.get(STORE_KEY) || [0, 0];- next(() =>- schedule("afterRender", () =>- this.scrollElement.scrollTo(...scrollLocation)- )- );+ next(() => this.scrollElement.scrollTo(...scrollLocation));}#shouldScroll(routeInfo) {diff --git a/app/assets/javascripts/discourse/app/services/scroll-direction.js b/app/assets/javascripts/discourse/app/services/scroll-direction.jsindex 0882915f43c..af78d327b77 100644--- a/app/assets/javascripts/discourse/app/services/scroll-direction.js+++ b/app/assets/javascripts/discourse/app/services/scroll-direction.js@@ -1,5 +1,5 @@import { tracked } from "@glimmer/tracking";-import { next, throttle } from "@ember/runloop";+import { throttle } from "@ember/runloop";import Service, { service } from "@ember/service";import discourseDebounce from "discourse/lib/debounce";import { bind } from "discourse/lib/decorators";@@ -49,11 +49,8 @@ export default class ScrollDirection extends Service {// User hasn't scrolled yet on this routethis.lastScrollDirection = UNSCROLLED;- // Wait for the initial DOM render to be done- next(() => {- // Then allow a bit of extra time for any DOM shifts to settle- discourseDebounce(this.unpause, PAUSE_AFTER_TRANSITION_MS);- });+ // Allow a bit of extra time for any DOM shifts to settle+ discourseDebounce(this.unpause, PAUSE_AFTER_TRANSITION_MS);}@binddiff --git a/app/assets/javascripts/select-kit/addon/components/select-kit.js b/app/assets/javascripts/select-kit/addon/components/select-kit.jsindex 20981bf52ca..b7fa22917a6 100644--- a/app/assets/javascripts/select-kit/addon/components/select-kit.js+++ b/app/assets/javascripts/select-kit/addon/components/select-kit.js@@ -1,7 +1,7 @@import Component from "@ember/component";import EmberObject, { computed, get } from "@ember/object";import { guidFor } from "@ember/object/internals";-import { bind, cancel, next, schedule, throttle } from "@ember/runloop";+import { bind, cancel, next, throttle } from "@ember/runloop";import { service } from "@ember/service";import { isEmpty, isNone, isPresent } from "@ember/utils";import {@@ -760,13 +760,11 @@ export default class SelectKit extends Component.extend(UtilsMixin) {_safeAfterRender(fn) {next(() => {- schedule("afterRender", () => {- if (!this.element || this.isDestroyed || this.isDestroying) {- return;- }+ if (!this.element || this.isDestroyed || this.isDestroying) {+ return;+ }- fn();- });+ fn();});}diff --git a/plugins/chat/assets/javascripts/discourse/lib/textarea-interactor.js b/plugins/chat/assets/javascripts/discourse/lib/textarea-interactor.jsindex efb792ed59b..a11578ae871 100644--- a/plugins/chat/assets/javascripts/discourse/lib/textarea-interactor.js+++ b/plugins/chat/assets/javascripts/discourse/lib/textarea-interactor.js@@ -49,37 +49,33 @@ export default class TextareaInteractor extends EmberObject {@bindblur() {next(() => {- schedule("afterRender", () => {- this.textarea.blur();- });+ this.textarea.blur();});}@bindfocus(opts = { ensureAtEnd: false, refreshHeight: true, addText: null }) {next(() => {- schedule("afterRender", () => {- if (opts.refreshHeight) {- this.refreshHeight();- }-- if (opts.ensureAtEnd) {- this.ensureCaretAtEnd();- }-- if (this.capabilities.isIpadOS || this.site.mobileView) {- return;- }-- if (opts.addText) {- this.textManipulation.addText(- this.textManipulation.getSelected(),- opts.addText- );- }-- this.textManipulation.blurAndFocus();- });+ if (opts.refreshHeight) {+ this.refreshHeight();+ }++ if (opts.ensureAtEnd) {+ this.ensureCaretAtEnd();+ }++ if (this.capabilities.isIpadOS || this.site.mobileView) {+ return;+ }++ if (opts.addText) {+ this.textManipulation.addText(+ this.textManipulation.getSelected(),+ opts.addText+ );+ }++ this.textManipulation.blurAndFocus();});}