From ac4c76d5fe67d0de2170d3b2707fd2053c1e7dd1 Mon Sep 17 00:00:00 2001 From: zackees Date: Sun, 7 Jun 2026 15:41:13 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20instant=20launch=20=E2=80=94=20explicit?= =?UTF-8?q?=20failure=20UX=20in=20the=20loading=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The instant-launch flow already exists: compile_and_serve starts the HTTP server, spawns the Tauri viewer, and only then runs the first compile — so the viewer opens within ~1s and serves LOADING_PAGE (which streams /build-stream SSE) while compilation happens behind it. On success, the page reloads to fetch the freshly-written index.html. This PR closes the remaining acceptance-criteria gaps in #148: * Error UX: previously a failed compile only updated the status text while the spinner kept spinning. Now setError() switches the spinner to red, stops the elapsed timer, and explicitly keeps the page on the build view (no navigation, no 404). * Elapsed time: new #elapsed counter alongside the status, useful on cold-cache first compiles. * Log clearing on rebuild: when a fresh 'compiling' status arrives after a prior build, the log is cleared and the timer reset so the user sees the new compile's output cleanly. Without this, a second failure would stack on top of the first. * Cleanup: removed a dead `const logEl = document.addEventListener(...)` binding that only captured undefined. New test test_loading_page_stays_when_build_failed_and_no_index_html seeds the server's output dir with a build-status.json of status=error and verifies GET / still returns 200 with the loading page (asserts the embedded setError branch is present). Verified: `soldr cargo test -p fastled-cli --lib server::` → 18 passed. Closes #148 Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/fastled-cli/src/server.rs | 127 ++++++++++++++++++++++++++----- 1 file changed, 107 insertions(+), 20 deletions(-) diff --git a/crates/fastled-cli/src/server.rs b/crates/fastled-cli/src/server.rs index 6b1b89a2..eb991a8c 100644 --- a/crates/fastled-cli/src/server.rs +++ b/crates/fastled-cli/src/server.rs @@ -49,24 +49,80 @@ const LOADING_PAGE: &str = r#" .spinner { width: 40px; height: 40px; border: 4px solid #333; border-top: 4px solid #4fc3f7; border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 20px; } + .spinner.error { border-top-color: #ef5350; animation: none; } @keyframes spin { to { transform: rotate(360deg); } } - #status { font-size: 1.2em; } + #header { font-size: 1.2em; display: flex; align-items: baseline; gap: 12px; } + #status { } + #elapsed { color: #888; font-size: 0.9em; } + #header.error #status { color: #ef5350; } #log { margin-top: 20px; width: 80%; max-height: 50vh; overflow-y: auto; font-size: 0.85em; color: #aaa; white-space: pre-wrap; text-align: left; line-height: 1.4; padding: 8px; background: #1a1a1a; border-radius: 4px; } -
-
Compiling...
+
+
"#; @@ -413,6 +470,36 @@ mod tests { ); } + /// Instant-launch failure UX (#148 acceptance criterion 5): + /// when a compile has failed and `index.html` is absent, `/` must still + /// return the in-browser loading page (which surfaces the error log) — + /// it must NOT 404 or navigate to a stale page. + #[tokio::test] + async fn test_loading_page_stays_when_build_failed_and_no_index_html() { + let (addr, dir) = setup_server().await; + fs::write( + dir.path().join("build-status.json"), + r#"{"status":"error","message":"Compilation failed"}"#, + ) + .unwrap(); + let resp = reqwest::get(format!("http://{addr}/")).await.unwrap(); + assert_eq!( + resp.status(), + 200, + "viewer should land on the loading page, not 404/redirect, when compile failed" + ); + let body = resp.text().await.unwrap(); + assert!( + body.contains("Compiling..."), + "expected loading page, got: {body}" + ); + // Sanity check: the embedded JS knows how to render the error state. + assert!( + body.contains("setError"), + "loading page must include error-handling branch" + ); + } + #[tokio::test] async fn test_serves_index_html_when_present() { let (addr, dir) = setup_server().await;