Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

perf(app-store): load RuntimeApp lazily so vaul leaves the first-load chunk

Abdurrahman Fakhrul9d2dc930828b
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 3092aaa7..f0064217 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -11,6 +11,10 @@ this is the *what*, and it is what Settings → Account → About shows as “Wh
- `perf` hydration mark chain, and the LCP conclusion it overturns
- `tui` close the opencode TUI gap on the seams MSO already owns (#166)
+**Faster**
+
+- `app-store` load RuntimeApp lazily so vaul leaves the first-load chunk
+
**Changed**
- `lib` drop static next/* imports, plus three measured perf findings
diff --git a/frontend/slices/app-store/lib/use-installed-apps.ts b/frontend/slices/app-store/lib/use-installed-apps.ts
index 8cff7e35..ceb079a8 100644
--- a/frontend/slices/app-store/lib/use-installed-apps.ts
+++ b/frontend/slices/app-store/lib/use-installed-apps.ts
@@ -1,11 +1,22 @@
"use client";
-import { useMemo } from "react";
+import { createElement, useMemo } from "react";
import type { AppDescriptor } from "./host";
import { glyphIcon } from "./glyph";
-import { RuntimeApp, type AppManifest } from "../components/runtime-app";
+import type { AppManifest } from "../components/runtime-app-types";
+import type { AppProps } from "../lib/host";
import { useApps } from "./apps-store";
+// `runtime-app` — and through it LegacyHtmlApp, AppConsole and the vaul drawer — is
+// imported dynamically, never at module scope. This hook runs in app/os-root.tsx, so a
+// static import here pulled that whole subtree into the catch-all's FIRST-LOAD chunk,
+// paid by every visitor including one who never installs or opens a runtime app.
+//
+// The promise is memoised so repeated window opens reuse one chunk fetch and one
+// evaluation, which is the contract `descriptor.load()` already promises callers.
+let runtimeAppModule: Promise<typeof import("../components/runtime-app")> | null = null;
+const loadRuntimeApp = () => (runtimeAppModule ??= import("../components/runtime-app"));
+
// Turns the owner's installed runtime apps (localStorage) into AppDescriptors
// the shell can mount — merged with the built-in slices by the app layer. This
// is the "dynamic" half of the registry: create/install an app → it appears live.
@@ -25,14 +36,20 @@ export function useInstalledApps(): AppDescriptor[] {
entry: a.entry,
source: a.source,
};
- const Comp = () => RuntimeApp({ manifest });
- Comp.displayName = `Runtime(${a.appId})`;
return {
id: a.appId,
title: a.title,
icon: glyphIcon(a.glyph),
gradient: a.gradient,
- load: () => Promise.resolve({ default: Comp }),
+ load: async () => {
+ const { RuntimeApp } = await loadRuntimeApp();
+ // A wrapper, not RuntimeApp itself: the manifest is bound here, so the
+ // descriptor's ComponentType<AppProps> signature stays honest. createElement
+ // because this module is .ts — JSX is not available here.
+ const Comp = (props: AppProps) => createElement(RuntimeApp, { manifest, ...props });
+ Comp.displayName = `Runtime(${a.appId})`;
+ return { default: Comp };
+ },
defaultSize: { w: 640, h: 460 },
};
});