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 <noreply@anthropic.com>
This commit is contained in:
Marian Paul
2026-01-17 21:30:49 +01:00
parent 5f786078fa
commit 32fb4dce09

View File

@@ -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...")