Skip to content

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.

perf(web): load the onboarding screens lazily and rebuild the shipped bundle

rubenluetke10-beep3f188fdb2fe8
diff --git a/jarvis/ui/web/frontend/src/components/onboarding/OnboardingGate.test.tsx b/jarvis/ui/web/frontend/src/components/onboarding/OnboardingGate.test.tsx
index 203fd99b53..7ddd2d426f 100644
--- a/jarvis/ui/web/frontend/src/components/onboarding/OnboardingGate.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/onboarding/OnboardingGate.test.tsx
@@ -72,7 +72,8 @@ it("persists terms acceptance when the risk gate is accepted", async () => {
render(<OnboardingGate />);
await waitFor(() => expect(screen.getByRole("dialog")).toBeDefined());
- fireEvent.click(screen.getByRole("checkbox"));
+ // RiskGate is a lazy chunk now — its controls appear only once it resolves.
+ fireEvent.click(await screen.findByRole("checkbox"));
fireEvent.click(screen.getByRole("button", { name: /continue/i }));
await waitFor(() =>
@@ -89,17 +90,20 @@ it("shows the tutorial video after the risk gate, then the step flow", async ()
render(<OnboardingGate />);
await waitFor(() => expect(screen.getByRole("dialog")).toBeDefined());
- // Accept the risk gate (tick the box, then the proceed button).
- fireEvent.click(screen.getByRole("checkbox"));
+ // Accept the risk gate (tick the box, then the proceed button). RiskGate is
+ // a lazy chunk, so its controls appear only once it resolves.
+ fireEvent.click(await screen.findByRole("checkbox"));
fireEvent.click(screen.getByRole("button", { name: /continue/i }));
- // Second screen: the tutorial video. It uses a click-to-play thumbnail
- // facade, so the YouTube embed only mounts once the user presses play.
- fireEvent.click(screen.getByRole("button", { name: /play the tutorial video/i }));
+ // Second screen: the tutorial video, its own lazy chunk. It uses a
+ // click-to-play thumbnail facade, so the YouTube embed only mounts once the
+ // user presses play.
+ fireEvent.click(await screen.findByRole("button", { name: /play the tutorial video/i }));
const frame = screen.getByTitle(/tour/i) as HTMLIFrameElement;
expect(frame.src).toContain("youtube-nocookie.com");
- // Continue past the video → the step flow renders.
+ // Continue past the video → the step flow (mocked, but still a lazy import)
+ // renders.
fireEvent.click(screen.getByRole("button", { name: /continue/i }));
- expect(screen.getByTestId("flow")).toBeDefined();
+ expect(await screen.findByTestId("flow")).toBeDefined();
});
diff --git a/jarvis/ui/web/frontend/src/components/onboarding/OnboardingGate.tsx b/jarvis/ui/web/frontend/src/components/onboarding/OnboardingGate.tsx
index 181cfd7b0c..4e12a5e20f 100644
--- a/jarvis/ui/web/frontend/src/components/onboarding/OnboardingGate.tsx
+++ b/jarvis/ui/web/frontend/src/components/onboarding/OnboardingGate.tsx
@@ -1,8 +1,23 @@
-import { useEffect, useMemo, useState } from "react";
+import { lazy, Suspense, useEffect, useMemo, useState } from "react";
import { useOnboarding } from "@/hooks/useOnboarding";
-import { OnboardingFlow } from "./OnboardingFlow";
-import { RiskGate } from "./RiskGate";
-import { IntroVideoScreen } from "./IntroVideoScreen";
+
+/**
+ * Code-split: a completed install renders this gate exactly once per mount —
+ * a no-op `null` return, forever — yet the risk screen, the intro video and
+ * the full six-step flow (with its own step components) used to travel in the
+ * entry chunk anyway, on every boot, for every returning user. Split the same
+ * way MainView.tsx splits section views: only the gate's own show/hide logic
+ * stays static, the screens load on the one boot that actually shows them.
+ */
+const OnboardingFlow = lazy(() =>
+ import("./OnboardingFlow").then((m) => ({ default: m.OnboardingFlow })),
+);
+const RiskGate = lazy(() =>
+ import("./RiskGate").then((m) => ({ default: m.RiskGate })),
+);
+const IntroVideoScreen = lazy(() =>
+ import("./IntroVideoScreen").then((m) => ({ default: m.IntroVideoScreen })),
+);
/**
* Blocking overlay that shows the onboarding flow until it is completed.
@@ -56,21 +71,25 @@ export function OnboardingGate() {
aria-modal="true"
className="fixed inset-0 z-50 flex items-center justify-center bg-background/90 backdrop-blur-sm"
>
- {!riskAck ? (
- <RiskGate
- onAccept={() => {
- // Persist the Terms record (fail-open: a warming/erroring backend
- // must never block the gate; the fast-boot path usually answers
- // immediately). The ack itself stays local-state-only by design.
- void onb.acceptTerms().catch(() => undefined);
- setRiskAck(true);
- }}
- />
- ) : showVideo ? (
- <IntroVideoScreen onContinue={() => setVideoSeen(true)} />
- ) : (
- <OnboardingFlow onb={onb} />
- )}
+ {/* Fallback is empty: the backdrop above already gives the user
+ something to look at while the first-run chunk fetches. */}
+ <Suspense fallback={null}>
+ {!riskAck ? (
+ <RiskGate
+ onAccept={() => {
+ // Persist the Terms record (fail-open: a warming/erroring backend
+ // must never block the gate; the fast-boot path usually answers
+ // immediately). The ack itself stays local-state-only by design.
+ void onb.acceptTerms().catch(() => undefined);
+ setRiskAck(true);
+ }}
+ />
+ ) : showVideo ? (
+ <IntroVideoScreen onContinue={() => setVideoSeen(true)} />
+ ) : (
+ <OnboardingFlow onb={onb} />
+ )}
+ </Suspense>
</div>
);
}