Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
perf(ui): load selected locale and chat view on demand
rubenluetke10-beep30d120815f29
diff --git a/jarvis/ui/web/frontend/src/i18n/index.ts b/jarvis/ui/web/frontend/src/i18n/index.tsindex d215368fbd..e0b7d31e66 100644--- a/jarvis/ui/web/frontend/src/i18n/index.ts+++ b/jarvis/ui/web/frontend/src/i18n/index.ts@@ -1,9 +1,9 @@/**- * Inhouse-i18n fuer die Desktop-App.+ * In-house i18n for the desktop app.*- * Warum kein react-i18next: 3 Sprachen, ~50 Strings, kein Pluralization-Bedarf,- * kein Backend-Lazy-Load. Eine Mini-Implementation auf Zustand spart 200 KB- * Bundle und einen npm-install-Schritt.+ * The small Zustand implementation avoids a framework dependency. English is+ * part of the first render; the other interface languages load on demand so+ * their full dictionaries do not delay the default startup path.** Usage:* import { useT } from "@/i18n";@@ -12,7 +12,7 @@** import { useUiLanguage, setUiLanguage } from "@/i18n";* const lang = useUiLanguage(); // "en" | "de" | "es"- * setUiLanguage("de"); // sofort reactive+ * setUiLanguage("de"); // updates reactively when loaded** STT recognition language (what Whisper transcribes the spoken voice INTO) is* its own setting, distinct from the UI and the reply language:@@ -21,8 +21,6 @@import { useEffect } from "react";import { create } from "zustand";import enJson from "./locales/en.json";-import deJson from "./locales/de.json";-import esJson from "./locales/es.json";import { useEventStore } from "@/store/events";export type UiLanguage = "en" | "de" | "es";@@ -65,16 +63,37 @@ function isSttLanguage(v: unknown): v is SttLanguage {const RESOURCES: Record<UiLanguage, Record<string, unknown>> = {en: enJson as Record<string, unknown>,- de: deJson as Record<string, unknown>,- es: esJson as Record<string, unknown>,+ de: enJson as Record<string, unknown>,+ es: enJson as Record<string, unknown>,};+const UI_LOCALE_LOADERS: Record<"de" | "es", () => Promise<unknown>> = {+ de: () => import("./locales/de.json"),+ es: () => import("./locales/es.json"),+};+const UI_LOCALE_PROMISES: Partial<Record<"de" | "es", Promise<void>>> = {};++/** Load a selected interface dictionary once and refresh mounted translations. */+export function loadUiLocale(lang: UiLanguage): Promise<void> {+ if (lang === "en") return Promise.resolve();+ if (UI_LOCALE_PROMISES[lang]) return UI_LOCALE_PROMISES[lang];+ const pending = UI_LOCALE_LOADERS[lang]().then((module) => {+ RESOURCES[lang] = unwrapModule(module);+ useI18nStore.setState((state) => ({ chunkRevision: state.chunkRevision + 1 }));+ }).catch((error: unknown) => {+ delete UI_LOCALE_PROMISES[lang];+ throw error;+ });+ UI_LOCALE_PROMISES[lang] = pending;+ return pending;+}+/*** Locale chunks that load on demand.*- * The three main locale files ride in the startup bundle, which has a byte- * budget (scripts/ci/check_frontend_bundle_budget.py). A section nobody opens- * on start — the marketplace's publish studio, say — keeps its strings in+ * English rides in the startup bundle; German and Spanish load on demand.+ * A section nobody opens on start — the marketplace's publish studio, say —+ * keeps its strings in* `locales/<chunk>/<lang>.json` and asks for them with `useLocaleChunk` when* it mounts. Until the chunk has arrived, `t()` returns the key, so a view* that cares waits for `ready` before it paints.@@ -328,6 +347,9 @@ export const useI18nStore = create<I18nState>((set) => ({/* ignore */}set({ ui: lang });+ void loadUiLocale(lang).catch((error: unknown) => {+ console.warn("Interface language could not be loaded", error);+ });// Default: propagate to the backend (the new source of truth). The WS// handler and hydrate pass push:false to avoid a GET/PUT echo loop.if (opts?.push !== false) {@@ -363,11 +385,8 @@ export const useI18nStore = create<I18nState>((set) => ({}));/**- * Resolve "nav.skills" zu dem String aus der aktiven Sprache.- * Fallback-Kette:- * 1. aktive Sprache- * 2. Englisch (Default)- * 3. der Key selbst (damit man nie "undefined" sieht)+ * Resolve a key from the active language, then English, then the key itself.+ * A failed optional dictionary load never renders an undefined label.*/function resolve(lang: UiLanguage, key: string): string {const parts = key.split(".");diff --git a/jarvis/ui/web/frontend/src/i18n/ui-locale-lazy.test.ts b/jarvis/ui/web/frontend/src/i18n/ui-locale-lazy.test.tsnew file mode 100644index 0000000000..9781e535ab--- /dev/null+++ b/jarvis/ui/web/frontend/src/i18n/ui-locale-lazy.test.ts@@ -0,0 +1,22 @@+import { afterEach, describe, expect, it } from "vitest";++import de from "./locales/de.json";+import es from "./locales/es.json";+import { loadUiLocale, translate, useI18nStore } from "./index";++afterEach(() => {+ useI18nStore.getState().setUi("en", { push: false });+});++describe("on-demand interface dictionaries", () => {+ it.each([+ ["de", de.common.loading],+ ["es", es.common.loading],+ ] as const)("resolves %s before showing its translated labels", async (lang, loading) => {+ const first = loadUiLocale(lang);+ expect(loadUiLocale(lang)).toBe(first);+ await first;+ useI18nStore.getState().setUi(lang, { push: false });+ expect(translate("common.loading")).toBe(loading);+ });+});diff --git a/jarvis/ui/web/frontend/src/main.tsx b/jarvis/ui/web/frontend/src/main.tsxindex 836d408738..55f8628e91 100644--- a/jarvis/ui/web/frontend/src/main.tsx+++ b/jarvis/ui/web/frontend/src/main.tsx@@ -8,6 +8,7 @@ import { AuthGate } from "./components/AuthGate";import { installPreloadRecovery } from "./lib/preloadRecovery";import { POLL_MS, installBundleWatch } from "./lib/bundleWatch";import { browserSafeReloadDeps, reloadWhenServable } from "./lib/safeReload";+import { loadUiLocale, useI18nStore } from "./i18n";import "./index.css";// When the frontend is rebuilt while the window is open, the old main bundle@@ -101,20 +102,26 @@ const queryClient = new QueryClient({},});-ReactDOM.createRoot(document.getElementById("root")!).render(- <React.StrictMode>- <QueryClientProvider client={queryClient}>- <ThemeProvider>- <ViewErrorBoundary- viewName="App"- resetKey="root"- onRecover={() => window.location.reload()}- >- <AuthGate>- <App />- </AuthGate>- </ViewErrorBoundary>- </ThemeProvider>- </QueryClientProvider>- </React.StrictMode>,-);+function renderApp(): void {+ ReactDOM.createRoot(document.getElementById("root")!).render(+ <React.StrictMode>+ <QueryClientProvider client={queryClient}>+ <ThemeProvider>+ <ViewErrorBoundary+ viewName="App"+ resetKey="root"+ onRecover={() => window.location.reload()}+ >+ <AuthGate>+ <App />+ </AuthGate>+ </ViewErrorBoundary>+ </ThemeProvider>+ </QueryClientProvider>+ </React.StrictMode>,+ );+}++void loadUiLocale(useI18nStore.getState().ui)+ .catch((error: unknown) => console.warn("Stored interface language could not be loaded", error))+ .finally(renderApp);diff --git a/jarvis/ui/web/frontend/src/views/ChatsSurface.test.tsx b/jarvis/ui/web/frontend/src/views/ChatsSurface.test.tsxindex 7fbe10ae6a..e8913be834 100644--- a/jarvis/ui/web/frontend/src/views/ChatsSurface.test.tsx+++ b/jarvis/ui/web/frontend/src/views/ChatsSurface.test.tsx@@ -38,7 +38,7 @@ describe("ChatsSurface (the front page)", () => {expect(screen.getByTestId("home-view").getAttribute("data-surface")).toBe("voice");});- it("switches to the chat stage from the sidebar switch and remembers it", () => {+ it("switches to the chat stage from the sidebar switch and remembers it", async () => {render(<><SurfaceSwitch />@@ -48,17 +48,17 @@ describe("ChatsSurface (the front page)", () => {fireEvent.click(screen.getByTestId("home-surface-chat"));- expect(screen.getByTestId("chat")).toBeTruthy();+ expect(await screen.findByTestId("chat")).toBeTruthy();expect(screen.queryByTestId("voice")).toBeNull();expect(window.localStorage.getItem(STORAGE_KEY)).toBe("chat");expect(screen.getByTestId("home-surface-chat").getAttribute("aria-selected")).toBe("true");});- it("opens on the chat stage when that is the stored choice", () => {+ it("opens on the chat stage when that is the stored choice", async () => {window.localStorage.setItem(STORAGE_KEY, "chat");useHomeStore.setState({ surface: readHomeSurface() });render(<ChatsSurface />);- expect(screen.getByTestId("chat")).toBeTruthy();+ expect(await screen.findByTestId("chat")).toBeTruthy();});it("switches back to voice", () => {diff --git a/jarvis/ui/web/frontend/src/views/HomeView.tsx b/jarvis/ui/web/frontend/src/views/HomeView.tsxindex 769cc20bd7..e6d4a6feeb 100644--- a/jarvis/ui/web/frontend/src/views/HomeView.tsx+++ b/jarvis/ui/web/frontend/src/views/HomeView.tsx@@ -1,7 +1,12 @@+import { lazy, Suspense } from "react";import { useHomeStore } from "@/store/home";import { HomeHeader } from "@/components/home/HomeHeader";import { VoiceStage } from "@/components/home/VoiceStage";-import { ChatStage } from "@/components/home/ChatStage";+import { useT } from "@/i18n";++const ChatStage = lazy(() =>+ import("@/components/home/ChatStage").then((module) => ({ default: module.ChatStage })),+);/*** The front page — the "chats" section.@@ -18,11 +23,16 @@ import { ChatStage } from "@/components/home/ChatStage";* no instruments, nothing that has to be read before you can speak.*/export function HomeView() {+ const t = useT();const surface = useHomeStore((s) => s.surface);return (<div className="flex h-full min-h-0 flex-col" data-testid="home-view" data-surface={surface}><HomeHeader />- {surface === "chat" ? <ChatStage /> : <VoiceStage />}+ {surface === "chat" ? (+ <Suspense fallback={<div role="status" className="flex min-h-0 flex-1 items-center justify-center text-sm text-muted-foreground">{t("common.loading")}</div>}>+ <ChatStage />+ </Suspense>+ ) : <VoiceStage />}</div>);}diff --git a/jarvis/ui/web/frontend/src/views/voice/DictationHistoryGroup.test.tsx b/jarvis/ui/web/frontend/src/views/voice/DictationHistoryGroup.test.tsxindex 964f5b9c2f..7244588373 100644--- a/jarvis/ui/web/frontend/src/views/voice/DictationHistoryGroup.test.tsx+++ b/jarvis/ui/web/frontend/src/views/voice/DictationHistoryGroup.test.tsx@@ -18,7 +18,7 @@ import { cleanup, render, screen } from "@testing-library/react";import { DictationHistoryGroup } from "@/views/voice/DictationHistoryGroup";import type { DictationEntry } from "@/hooks/useDictation";-import { setUiLanguage } from "@/i18n";+import { loadUiLocale, setUiLanguage } from "@/i18n";function entry(over: Partial<DictationEntry> = {}): DictationEntry {return {@@ -133,7 +133,8 @@ describe("DictationHistoryGroup — cleanup-reason badge", () => {expect(screen.queryByTestId("dictation-cleanup-reason-badge")).toBeNull();});- it("translates both badges into the user's language", () => {+ it("translates both badges into the user's language", async () => {+ await loadUiLocale("de");setUiLanguage("de");renderRows([entry({ polish_status: "applied", cleanup_reason: "no_rules" })]);