Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client): show the worker's real startup phases, and stop the bar shrinking
Claude3853db28f7b0
diff --git a/apps/client/index.html b/apps/client/index.htmlindex 184bbb3184..134b6bd465 100644--- a/apps/client/index.html+++ b/apps/client/index.html@@ -71,6 +71,9 @@animation: none;transition: width 12s cubic-bezier(0.16, 0.85, 0.3, 1);}+ #splash .splash-bar.is-continuous.is-starting .splash-bar-fill {+ transition: none;+ }#splash .splash-bar.is-continuous.is-finishing .splash-bar-fill {transition: width 0.3s ease;}diff --git a/apps/client/src/services/splash.ts b/apps/client/src/services/splash.tsindex 38daebfe5d..fc7b00b42a 100644--- a/apps/client/src/services/splash.ts+++ b/apps/client/src/services/splash.ts@@ -55,7 +55,16 @@ export function initSplashProgress(startupPhases: SplashPhase[]): void {phases = startupPhases;totalWeight = phases.reduce((sum, phase) => sum + phase.weight, 0);- document.querySelector("#splash .splash-bar")?.classList.add("is-continuous");+ const bar = document.querySelector("#splash .splash-bar");+ if (!bar) {+ return;+ }++ // The indeterminate fill sits at 40% of the bar, which is further along than most startups+ // begin. Dropping to the real starting position has to skip the long ease, or the bar spends+ // its first seconds visibly shrinking; the guard is lifted a frame later, once 0 has landed.+ bar.classList.add("is-continuous", "is-starting");+ requestAnimationFrame(() => bar.classList.remove("is-starting"));}/**diff --git a/apps/standalone/src/index.html b/apps/standalone/src/index.htmlindex f2611a9088..208a55d182 100644--- a/apps/standalone/src/index.html+++ b/apps/standalone/src/index.html@@ -71,6 +71,9 @@animation: none;transition: width 12s cubic-bezier(0.16, 0.85, 0.3, 1);}+ #splash .splash-bar.is-continuous.is-starting .splash-bar-fill {+ transition: none;+ }#splash .splash-bar.is-continuous.is-finishing .splash-bar-fill {transition: width 0.3s ease;}diff --git a/apps/standalone/src/main.spec.ts b/apps/standalone/src/main.spec.tsindex e06ca01876..a8ff552ab2 100644--- a/apps/standalone/src/main.spec.ts+++ b/apps/standalone/src/main.spec.ts@@ -132,11 +132,29 @@ describe("bootstrap", () => {await vi.waitFor(() => expect(sw.register).toHaveBeenCalled());expect(document.getElementById("splash-status")?.textContent).toBe("Setting up offline support…");- // Eight weighted phases, the first of which covers 1/18 of the bar.+ // Seven weighted phases, the first of which covers 1/17 of the bar.const fill = document.querySelector<HTMLElement>(".splash-bar-fill");expect(fill?.style.width).toBe("6%");});+ it("lets the worker's phases through after the client reports its own", async () => {+ document.body.innerHTML = `+ <div id="splash">+ <div class="splash-bar"><div class="splash-bar-fill"></div></div>+ <div id="splash-status"></div>+ </div>`;+ setServiceWorker({ controller: {}, register: vi.fn(), ready: Promise.resolve() });+ await runBootstrap();+ const { reportSplashPhase } = await import("../../client/src/services/splash.js");++ // On a warm start the client reaches its own "bootstrap" phase while the worker is still+ // opening the database. That phase is not in the standalone sequence, so the worker's+ // later steps are still shown rather than being swallowed by the monotonic guard.+ reportSplashPhase("bootstrap");+ reportSplashPhase("core");+ expect(document.getElementById("splash-status")?.textContent).toBe("Loading Trilium…");+ });+it("reloads the page when the SW installs but does not take control", async () => {setServiceWorker({ controller: null, register: vi.fn().mockResolvedValue(undefined), ready: Promise.resolve() });await runBootstrap();diff --git a/apps/standalone/src/main.ts b/apps/standalone/src/main.tsindex 1ae4e6a8a6..27c102aed6 100644--- a/apps/standalone/src/main.ts+++ b/apps/standalone/src/main.ts@@ -14,15 +14,19 @@ import { announceLeadership, attachServiceWorkerBridge, downloadDatabase, regist* The worker reports the middle of this sequence over `STARTUP_PROGRESS` (see local-bridge.ts).* A follower tab has no worker of its own, so it sits on the first phase until the leader answers* its `/bootstrap` and the client's own phases carry the bar the rest of the way.+ *+ * The client's own `bootstrap` phase is deliberately absent: here `/bootstrap` is answered by the+ * worker, so it does not follow the worker's steps but spans them. Listing it would let index.ts+ * report it while the worker was still on `sqlite`, and the monotonic guard in reportSplashPhase()+ * would then swallow every later worker phase.*/const STANDALONE_STARTUP_PHASES: SplashPhase[] = [{ id: "service-worker", weight: 1, status: "Setting up offline support…" },- { id: "worker-modules", weight: 1, status: "Starting the database engine…" },+ { id: "worker-modules", weight: 1, status: "Starting up…" },{ id: "sqlite", weight: 3, status: "Loading the database engine…" },{ id: "database", weight: 2, status: "Opening the database…" },{ id: "core", weight: 4, status: "Loading Trilium…" },{ id: "becca", weight: 2, status: "Reading your notes…" },- { id: "bootstrap", weight: 1, status: "Preparing the workspace…" },{ id: "application", weight: 4, status: "Loading the application…" }];