Skip to content

Commit

Permalink
refactor: load wasm dependency pre-routing
Browse files Browse the repository at this point in the history
This way, the Prose loader shows during the time of the WASM dependency loading. Before this refactor was done, there would be a time between the bootloader logo and the app first paint where the app would show as white, as the WASM loading would block routing.
  • Loading branch information
valeriansaliou committed Oct 18, 2023
1 parent 91bf55b commit c365d6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
7 changes: 7 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// NPM
import { createApp } from "vue";
import { default as proseSDKJS } from "@prose-im/prose-sdk-js";

// PROJECT: STYLES
import "@/assets/stylesheets/all.scss";
Expand All @@ -28,6 +29,12 @@ import BootstrapFilters from "@/bootstrap/filters";
import BootstrapComponents from "@/bootstrap/components";
import BootstrapPlugins from "@/bootstrap/plugins";

/**************************************************************************
* DEPENDENCIES
* ************************************************************************* */

await proseSDKJS();

/**************************************************************************
* INSTANCES
* ************************************************************************* */
Expand Down
26 changes: 5 additions & 21 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
createRouter,
createWebHistory
} from "vue-router";
import init, { JID } from "@prose-im/prose-sdk-js";
import { JID } from "@prose-im/prose-sdk-js";

// PROJECT: VIEWS
import AppBase from "@/views/app/AppBase.vue";
Expand Down Expand Up @@ -50,7 +50,6 @@ enum NavigateState {
class Router {
private readonly __router: VueRouter;

private __wasmModuleInitialized = false;
private __lastNavigateStatePosition = 0;
private __pendingNavigateState: NavigateState | null = null;

Expand All @@ -70,8 +69,7 @@ class Router {
component: StartLogin,

beforeEnter: (_to, _from, next) => {
this.__initializeWasmModule()
.then(this.__guardAnonymous.bind(this))
this.__guardAnonymous()
.then(next)
.catch(error => {
if (error) {
Expand All @@ -89,8 +87,7 @@ class Router {
component: AppBase,

beforeEnter: (_to, _from, next) => {
this.__initializeWasmModule()
.then(this.__guardAuthenticated.bind(this))
this.__guardAuthenticated()
.then(this.__setupBrokerClient.bind(this))
.then(next)
.catch(error => {
Expand Down Expand Up @@ -130,16 +127,7 @@ class Router {
app.use(this.__router);
}

private async __initializeWasmModule() {
// Not already initialized?
if (this.__wasmModuleInitialized !== true) {
this.__wasmModuleInitialized = true;

await init();
}
}

private __guardAuthenticated(): Promise<void> {
private async __guardAuthenticated(): Promise<void> {
// Ensure that user is logged in (redirect to base if not)
if (!Store.$account.credentials.jid) {
this.__router.push({
Expand All @@ -148,11 +136,9 @@ class Router {

return Promise.reject();
}

return Promise.resolve();
}

private __guardAnonymous(): Promise<void> {
private async __guardAnonymous(): Promise<void> {
// Ensure that user is not logged-in (redirect to app if so)
if (Store.$account.credentials.jid) {
this.__router.push({
Expand All @@ -161,8 +147,6 @@ class Router {

return Promise.reject();
}

return Promise.resolve();
}

private async __setupBrokerClient(): Promise<void> {
Expand Down

0 comments on commit c365d6d

Please sign in to comment.