diff options
| author | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-06-01 10:44:45 +0900 |
|---|---|---|
| committer | syuilo <4439005+syuilo@users.noreply.github.com> | 2025-06-01 10:44:45 +0900 |
| commit | f4167ae7f1df7c2cd4cf264fc4d79d51b8c51133 (patch) | |
| tree | 9f87a9ee76c82176daa4e81f1b117e90ec933f52 /packages/frontend/src/os.ts | |
| parent | fix(frontend): remove unused text (diff) | |
| download | misskey-f4167ae7f1df7c2cd4cf264fc4d79d51b8c51133.tar.gz misskey-f4167ae7f1df7c2cd4cf264fc4d79d51b8c51133.tar.bz2 misskey-f4167ae7f1df7c2cd4cf264fc4d79d51b8c51133.zip | |
enhance(frontend): 非同期的なコンポーネントの読み込み時のハンドリングを強化
Diffstat (limited to 'packages/frontend/src/os.ts')
| -rw-r--r-- | packages/frontend/src/os.ts | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/packages/frontend/src/os.ts b/packages/frontend/src/os.ts index 08291a5595..d50f50cf20 100644 --- a/packages/frontend/src/os.ts +++ b/packages/frontend/src/os.ts @@ -206,6 +206,52 @@ export function popup<T extends Component>( }; } +export async function popupAsyncWithDialog<T extends Component>( + componentFetching: Promise<T>, + props: ComponentProps<T>, + events: Partial<ComponentEmit<T>> = {}, +): Promise<{ dispose: () => void }> { + const closeWaiting = waiting(); + + let component: T; + + try { + component = await componentFetching; + } catch (err) { + closeWaiting(); + alert({ + type: 'error', + title: i18n.ts.somethingHappened, + text: 'CODE: ASYNC_COMP_LOAD_FAIL', + }); + throw err; + } + + closeWaiting(); + + markRaw(component); + + const id = ++popupIdCount; + const dispose = () => { + // このsetTimeoutが無いと挙動がおかしくなる(autocompleteが閉じなくなる)。Vueのバグ? + window.setTimeout(() => { + popups.value = popups.value.filter(p => p.id !== id); + }, 0); + }; + const state = { + component, + props, + events, + id, + }; + + popups.value.push(state); + + return { + dispose, + }; +} + export function pageWindow(path: string) { const { dispose } = popup(MkPageWindow, { initialPath: path, @@ -787,9 +833,9 @@ export function launchUploader( multiple?: boolean; }, ): Promise<Misskey.entities.DriveFile[]> { - return new Promise((res, rej) => { + return new Promise(async (res, rej) => { if (files.length === 0) return rej(); - const { dispose } = popup(defineAsyncComponent(() => import('@/components/MkUploaderDialog.vue')), { + const { dispose } = await popupAsyncWithDialog(import('@/components/MkUploaderDialog.vue').then(x => x.default), { files: markRaw(files), folderId: options?.folderId, multiple: options?.multiple, |