A platform for community discussion. Free, open, simple.
DEV: Add missing `waitForPromise` calls (#38819)
David Taylore47fc27a9be2
diff --git a/frontend/discourse/app/components/form-template-field/wrapper.gjs b/frontend/discourse/app/components/form-template-field/wrapper.gjsindex 6e132771dc3..29b994949cd 100644--- a/frontend/discourse/app/components/form-template-field/wrapper.gjs+++ b/frontend/discourse/app/components/form-template-field/wrapper.gjs@@ -4,7 +4,7 @@ import { action, get } from "@ember/object";import didUpdate from "@ember/render-modifiers/modifiers/did-update";import { next } from "@ember/runloop";import { service } from "@ember/service";-import Yaml from "js-yaml";+import { waitForPromise } from "@ember/test-waiters";import FormTemplate from "discourse/models/form-template";import CheckboxField from "./checkbox";import ComposerField from "./composer";@@ -65,8 +65,11 @@ export default class FormTemplateFieldWrapper extends Component {});}- _loadTemplate(templateContent) {+ async _loadTemplate(templateContent) {try {+ const promise = import("js-yaml");+ waitForPromise(promise);+ const Yaml = (await promise).default;this.parsedTemplate = Yaml.load(templateContent);this.args.onSelectFormTemplate?.(this.parsedTemplate);} catch (e) {diff --git a/frontend/discourse/app/components/modal/spreadsheet-editor.gjs b/frontend/discourse/app/components/modal/spreadsheet-editor.gjsindex b6979f9d786..b03bd013604 100644--- a/frontend/discourse/app/components/modal/spreadsheet-editor.gjs+++ b/frontend/discourse/app/components/modal/spreadsheet-editor.gjs@@ -3,6 +3,7 @@ import { tracked } from "@glimmer/tracking";import { action } from "@ember/object";import didInsert from "@ember/render-modifiers/modifiers/did-insert";import { service } from "@ember/service";+import { waitForPromise } from "@ember/test-waiters";import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";import DButton from "discourse/components/d-button";import DModal from "discourse/components/d-modal";@@ -127,11 +128,13 @@ export default class SpreadsheetEditor extends Component {}async loadJspreadsheet() {- const [jspreadsheetModule] = await Promise.all([- import("jspreadsheet-ce"),- import("jspreadsheet-ce/dist/jspreadsheet.css"),- import("jsuites/dist/jsuites.css"),- ]);+ const [jspreadsheetModule] = await waitForPromise(+ Promise.all([+ import("jspreadsheet-ce"),+ import("jspreadsheet-ce/dist/jspreadsheet.css"),+ import("jsuites/dist/jsuites.css"),+ ])+ );this.jspreadsheet = jspreadsheetModule.default;this.jspreadsheet.setDictionary(this.localeMapping());diff --git a/frontend/discourse/app/lib/composer/rich-editor-extensions.js b/frontend/discourse/app/lib/composer/rich-editor-extensions.jsindex dd471a92546..199c9d3041d 100644--- a/frontend/discourse/app/lib/composer/rich-editor-extensions.js+++ b/frontend/discourse/app/lib/composer/rich-editor-extensions.js@@ -1,5 +1,7 @@// @ts-check+import { waitForPromise } from "@ember/test-waiters";+/*** @typedef PluginContext* @property {string} placeholder@@ -149,8 +151,9 @@ export function clearRichEditorExtensions() {}export async function resetRichEditorExtensions() {- const { default: extensions } =- await import("discourse/static/prosemirror/extensions/register-default");+ const { default: extensions } = await waitForPromise(+ import("discourse/static/prosemirror/extensions/register-default")+ );clearRichEditorExtensions();extensions.forEach(registerRichEditorExtension);}diff --git a/frontend/discourse/app/lib/lightbox.js b/frontend/discourse/app/lib/lightbox.jsindex 51f6ec57c75..f78de3d4b3f 100644--- a/frontend/discourse/app/lib/lightbox.js+++ b/frontend/discourse/app/lib/lightbox.js@@ -36,7 +36,9 @@ async function initLightbox(elem, additionalData = {}) {const siteSettings = helperContext().siteSettings;const caps = helperContext().capabilities;- const { default: PhotoSwipeLightbox } = await import("photoswipe/lightbox");+ const { default: PhotoSwipeLightbox } = await waitForPromise(+ import("photoswipe/lightbox")+ );const isTestEnv = isTesting() || isRailsTesting();const canDownload =!siteSettings.prevent_anons_from_downloading_files || !!currentUser;@@ -68,7 +70,7 @@ async function initLightbox(elem, additionalData = {}) {escKey: false,tapAction,paddingFn,- pswpModule: async () => await import("photoswipe"),+ pswpModule: async () => await waitForPromise(import("photoswipe")),appendToEl: isTesting() && document.getElementById("ember-testing"),});diff --git a/frontend/discourse/app/lib/load-faker.js b/frontend/discourse/app/lib/load-faker.jsindex 8c42c39d7f4..77b0fdb8189 100644--- a/frontend/discourse/app/lib/load-faker.js+++ b/frontend/discourse/app/lib/load-faker.js@@ -1,3 +1,5 @@+import { waitForPromise } from "@ember/test-waiters";+let faker;/*@@ -5,7 +7,7 @@ Plugins & themes are unable to async-import npm modules directly.This wrapper provides them with a way to use fakerjs, while keeping the `import()` in core's codebase.*/export default async function loadFaker() {- faker ??= await import("@faker-js/faker");+ faker ??= await waitForPromise(import("@faker-js/faker"));return faker;}diff --git a/frontend/discourse/app/lib/load-js-diff.js b/frontend/discourse/app/lib/load-js-diff.jsindex a5b112b521c..4578b60c34d 100644--- a/frontend/discourse/app/lib/load-js-diff.js+++ b/frontend/discourse/app/lib/load-js-diff.js@@ -1,10 +1,13 @@+import { waitForPromise } from "@ember/test-waiters";+/*Plugins & themes are unable to async-import npm modules directly.This wrapper provides them with a way to use morphlex, while keeping the `import()` in core's codebase.*/+/*** @returns {Promise<import("diff")>}*/export default async function loadJSDiff() {- return await import("diff");+ return await waitForPromise(import("diff"));}diff --git a/frontend/discourse/app/lib/load-morphlex.js b/frontend/discourse/app/lib/load-morphlex.jsindex eb2c0ea7e46..61d87f191c4 100644--- a/frontend/discourse/app/lib/load-morphlex.js+++ b/frontend/discourse/app/lib/load-morphlex.js@@ -1,7 +1,9 @@+import { waitForPromise } from "@ember/test-waiters";+/*Plugins & themes are unable to async-import npm modules directly.This wrapper provides them with a way to use morphlex, while keeping the `import()` in core's codebase.*/export default async function loadMorphlex() {- return await import("morphlex");+ return await waitForPromise(import("morphlex"));}diff --git a/frontend/discourse/app/lib/load-rich-editor.js b/frontend/discourse/app/lib/load-rich-editor.jsindex 046404e3c85..b0d12a4be6a 100644--- a/frontend/discourse/app/lib/load-rich-editor.js+++ b/frontend/discourse/app/lib/load-rich-editor.js@@ -1,5 +1,9 @@+import { waitForPromise } from "@ember/test-waiters";+export default async function loadRichEditor() {return (- await import("discourse/static/prosemirror/components/prosemirror-editor")+ await waitForPromise(+ import("discourse/static/prosemirror/components/prosemirror-editor")+ )).default;}diff --git a/frontend/discourse/app/lib/text.js b/frontend/discourse/app/lib/text.jsindex fc861555870..9d19761219d 100644--- a/frontend/discourse/app/lib/text.js+++ b/frontend/discourse/app/lib/text.js@@ -1,3 +1,4 @@+import { waitForPromise } from "@ember/test-waiters";import AllowLister from "pretty-text/allow-lister";import { buildEmojiUrl, performEmojiUnescape } from "pretty-text/emoji";import { sanitize as textSanitize } from "pretty-text/sanitizer";@@ -7,7 +8,7 @@ import { helperContext } from "discourse/lib/helpers";import { i18n } from "discourse-i18n";async function withEngine(name, ...args) {- const engine = await import("discourse/static/markdown-it");+ const engine = await waitForPromise(import("discourse/static/markdown-it"));return engine[name](...args);}diff --git a/frontend/discourse/app/static/prosemirror/components/image-node-view.gjs b/frontend/discourse/app/static/prosemirror/components/image-node-view.gjsindex 26738e7b5ce..46d8c2e216d 100644--- a/frontend/discourse/app/static/prosemirror/components/image-node-view.gjs+++ b/frontend/discourse/app/static/prosemirror/components/image-node-view.gjs@@ -5,6 +5,7 @@ import { action } from "@ember/object";import didInsert from "@ember/render-modifiers/modifiers/did-insert";import { service } from "@ember/service";import { trustHTML } from "@ember/template";+import { waitForPromise } from "@ember/test-waiters";import { NodeSelection } from "prosemirror-state";import ToolbarButtons from "discourse/components/composer/toolbar-buttons";import { ToolbarBase } from "discourse/lib/composer/toolbar";@@ -627,7 +628,9 @@ async function openLightbox(editorElement, currentImage) {};});- const { default: PhotoSwipeLightbox } = await import("photoswipe/lightbox");+ const { default: PhotoSwipeLightbox } = await waitForPromise(+ import("photoswipe/lightbox")+ );const isTestEnv = isTesting() || isRailsTesting();const lightbox = new PhotoSwipeLightbox({@@ -637,7 +640,7 @@ async function openLightbox(editorElement, currentImage) {zoomTitle: i18n("lightbox.zoom"),arrowPrevTitle: i18n("lightbox.previous"),arrowNextTitle: i18n("lightbox.next"),- pswpModule: () => import("photoswipe"),+ pswpModule: () => waitForPromise(import("photoswipe")),tapAction: (pt, e) => {if (e.target.classList.contains("pswp__img")) {lightbox.pswp?.element?.classList.toggle("pswp--ui-visible");