diff --git a/framework/core/js/src/common/components/TextEditor.js b/framework/core/js/src/common/components/TextEditor.js index 249d60eb8d..4c41e80fd0 100644 --- a/framework/core/js/src/common/components/TextEditor.js +++ b/framework/core/js/src/common/components/TextEditor.js @@ -72,9 +72,7 @@ export default class TextEditor extends Component { oncreate(vnode) { super.oncreate(vnode); - this._load().then(() => { - setTimeout(this.onbuild.bind(this), 50); - }); + this._load().then(this.onbuild.bind(this)); } onbuild() { @@ -96,7 +94,12 @@ export default class TextEditor extends Component { _load() { return Promise.all(this._loaders.map((loader) => loader())).then(() => { this.loading = false; - m.redraw(); + // Synchronous redraw so the editor container is in the DOM before + // `onbuild` runs. Mithril's regular `m.redraw()` queues for the next + // frame, which previously raced against a 50ms setTimeout and could + // leave `this.$('.TextEditor-editorContainer')[0]` undefined on slow + // first loads. See flarum/framework#4612. + m.redraw.sync(); }); }