From 32fb4dce093b3359222ca66160886211a0966d72 Mon Sep 17 00:00:00 2001 From: Marian Paul Date: Sat, 17 Jan 2026 21:30:49 +0100 Subject: [PATCH] fix: improve UI build detection to check source file timestamps Enhance the build_frontend() function to detect when source files have been modified more recently than the newest file in dist/ directory. This ensures the UI is rebuilt automatically when source code changes, preventing stale UI from being served after pulling updates or switching branches. Changes: - Find newest modification time among all files in ui/dist/ - Compare each source file in ui/src/ against newest dist file - Trigger rebuild if any source file is newer than newest dist file - Handle edge case when dist/ exists but contains no files - Prevent serving outdated JavaScript bundles after code changes This fix applies to all UI launch methods (start_ui.sh, start_ui.bat) since they all call start_ui.py which contains the build logic. Co-Authored-By: Claude Sonnet 4.5 --- start_ui.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/start_ui.py b/start_ui.py index 267ae12..59fd204 100644 --- a/start_ui.py +++ b/start_ui.py @@ -141,11 +141,36 @@ def install_npm_deps() -> bool: def build_frontend() -> bool: - """Build the React frontend if dist doesn't exist.""" + """Build the React frontend if dist doesn't exist or is stale.""" dist_dir = UI_DIR / "dist" + src_dir = UI_DIR / "src" - if dist_dir.exists(): - print(" Frontend already built") + # Check if build is needed + needs_build = False + + if not dist_dir.exists(): + needs_build = True + elif src_dir.exists(): + # Find the newest file in dist/ directory + newest_dist_mtime = 0 + for dist_file in dist_dir.rglob("*"): + if dist_file.is_file(): + file_mtime = dist_file.stat().st_mtime + if file_mtime > newest_dist_mtime: + newest_dist_mtime = file_mtime + + # Check if any source file is newer than the newest dist file + if newest_dist_mtime > 0: + for src_file in src_dir.rglob("*"): + if src_file.is_file() and src_file.stat().st_mtime > newest_dist_mtime: + needs_build = True + break + else: + # No files found in dist, need to rebuild + needs_build = True + + if not needs_build: + print(" Frontend already built (up to date)") return True print(" Building React frontend...")