Public: anyone can read this; the crew can change it.

Lazy-load the boards, studio and the other optional modules a small forge never uses #12373

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/12372-lazy-load-the-boards-studio-and-the-othe → main 5 commits fork 4 threads · 4 unresolved

  • Merged. torque/12372-lazy-load-the-boards-studio-and-the-othe was merged into main as b4c82c4.

Review

Sign in to review this change.
2 files changed +14 −2
src/main.ts +10 −2
@@ -54,7 +54,6 @@ import { runGuardSweep } from "./origins/credential.ts";
5454 import { warmHome } from "./web/pages/home_flow.ts";
5555 import { warmPlans } from "./web/pages/milestones.ts";
5656 import { warmBoards } from "./web/pages/boards-view.ts";
57 import { startForgeSsh } from "./tui/ssh.ts";
5857 import { AppsRuntime, IDLE_PULL_DAYS } from "./apps/runtime.ts";
5958 import { previewIdleMs } from "./apps/sleep_window.ts";
6059 import { listApps } from "./core/apps.ts";
@@ -434,8 +433,17 @@ keepFlowReadings(KEPT_MS);
434433 // The home's picture is read by a worker from here, so the first page finds it (web/pages/home_flow.ts).
435434 warmHome(app);
outdated

Unrelated to what the router loads anyway; sshPort > 0 lazy import is good, keep it. Add a log on failure instead of silence.

436435 warmBoards(app);
436 // The terminal is optional: its modules load only when a port is set, so a forge with
437 // FORGE_SSH_PORT=0 never loads them (test/boot-lazy.test.ts).
437438 const sshStarted =
438 sshPort > 0 ? await startForgeSsh(app, { port: sshPort }) : undefined;
439 sshPort > 0
440 ? await import("./tui/ssh.ts")

Non-blocking: this catch also swallows errors thrown by startForgeSsh, not only the import, and reports them as a load failure.

441 .then((m) => m.startForgeSsh(app, { port: sshPort }))
442 .catch((error) => {
443 app.log.warn("ssh is off: the terminal failed to load", { error: String(error) });
444 return undefined;
445 })
446 : undefined;
439447 if (sshStarted && !sshStarted.ok)
440448 app.log.warn("ssh is off: the terminal could not start", {
441449 port: sshPort,
test/boot-lazy.test.ts +4
@@ -28,3 +28,7 @@ test("the boot's static imports do not reach the terminal UI", () => {
2828 const tui = closure.filter((f) => f.includes("/src/tui/screens/") || f.endsWith("/src/tui/forge.ts"));
2929 expect(tui).toEqual([]);
3030 });
31
32 test("the terminal's server is imported dynamically by the boot", () => {
33 expect(readFileSync(resolve("src/main.ts"), "utf8")).toContain('import("./tui/ssh.ts")');
34 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs