From 3bde72a71b7ae430dea1d652367e7b24984b4b29 Mon Sep 17 00:00:00 2001 From: Kasper Seweryn Date: Mon, 18 Apr 2022 01:24:50 +0200 Subject: [PATCH] Wait for all modules to load --- front/src/App.vue | 1 - front/src/main.ts | 24 +++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/front/src/App.vue b/front/src/App.vue index 7578f1fb3..389addcbe 100644 --- a/front/src/App.vue +++ b/front/src/App.vue @@ -221,5 +221,4 @@ const showSetInstanceModal = ref(false) diff --git a/front/src/main.ts b/front/src/main.ts index 2348e6db1..07e266c07 100644 --- a/front/src/main.ts +++ b/front/src/main.ts @@ -1,5 +1,4 @@ import logger from '~/logging' -import App from '~/App.vue' import router from '~/router' import VueLazyload from 'vue-lazyload' import store from '~/store' @@ -15,21 +14,36 @@ sync(store, router) const app = createApp({ store, router, - render: (h: CreateElement) => h(App) + data: () => ({ isMounted: false }), + async mounted () { + this.isMounted = true + }, + render (h: CreateElement) { + if (this.isMounted) { + return import('~/App.vue') + } + + // TODO (wvffle): Import fake app component + return h() + } }) app.use(VueCompositionAPI) app.use(VueLazyload) +const modules: Promise[] = [] for (const module of Object.values(import.meta.globEager('./modules/*.ts'))) { - module.install?.({ + modules.push(module.install?.({ app, router, store - }) + })) } -store.dispatch('instance/fetchFrontSettings').finally(() => { +store.dispatch('instance/fetchFrontSettings').finally(async () => { + // Wait for all modules to load + await Promise.all(modules) + app.mount('#app') logger.default.info('Everything loaded!') })