HTML Generation Issues Resolution
Overview
This document describes the comprehensive fixes implemented to resolve three critical issues with HTML generation in the Sasha Studio documentation system.
Issues Resolved
1. Toast Notification Never Dismisses
Problem: The "Generating HTML reports..." toast would remain spinning indefinitely, never showing completion status.
Root Cause: Toast dismissal logic was conditional and could fail to execute in error scenarios.
Solution:
- Always dismiss loading toast immediately after receiving server response
- Moved
toast.dismiss(toastId)to execute before conditional logic - Added proper error message extraction from server response
// Before: Conditional dismissal
if (response.data && response.data.success) {
toast.dismiss(toastId);
// success handling
} else {
toast.dismiss(toastId); // Could be missed
}
// After: Always dismiss first
toast.dismiss(toastId);
if (response.data && response.data.success) {
// success handling
} else {
// error handling
}
2. No Initial HTML Content on Docker Startup
Problem: Even when markdown files existed, no HTML documentation was available until manual generation.
Root Cause: HTML generation only occurred on manual trigger, not during container initialization.
Solution:
- Stage 1: Generate SPA content-only HTML immediately during startup
- Stage 2: Generate full HTML documentation after server becomes ready
- Background process ensures non-blocking container startup
Implementation:
# docker-entrypoint.sh
# Generate SPA content immediately
node /app/scripts/generate-spa-html.js
# Schedule full HTML generation after server startup
(sleep 10 && node /app/scripts/generate-initial-html.js) &
3. Auto-Refresh Doesn't Work
Problem: After generating HTML, the documentation iframe didn't refresh automatically, requiring manual browser refresh.
Root Cause: DocsPanel iframe wasn't listening for live-reload WebSocket messages.
Solution:
- Added WebSocket connection to live-reload endpoint
- Added custom event listener for immediate refresh triggers
- Proper cleanup on component unmount
Implementation:
// Dual refresh mechanism
const handleDocsGenerated = () => setRefreshKey(prev => prev + 1);
window.addEventListener('docs-generated', handleDocsGenerated);
// WebSocket live-reload
const ws = new WebSocket(`${protocol}//${window.location.host}/live-reload`);
ws.onmessage = (event) => {
if (event.data === 'reload') {
setRefreshKey(prev => prev + 1);
}
};
Architecture Changes
Container Startup Flow
User Interaction Flow
Files Modified
1. src/components/FileTree.jsx
- Fixed toast dismissal logic in
handleGenerateReports() - Added custom event dispatch for DocsPanel refresh
- Improved error handling and message extraction
2. src/components/DocsPanel.jsx
- Added WebSocket connection for live-reload
- Added custom event listener for immediate refresh
- Proper cleanup in useEffect return function
3. docker-entrypoint.sh
- Added immediate SPA content generation
- Added background full HTML generation
- Non-blocking startup process
4. scripts/generate-initial-html.js (New)
- Server readiness checking with retry logic
- API-based HTML generation trigger
- Graceful error handling with fallback
Testing Scenarios
Scenario 1: Fresh Container Startup
- Container starts with markdown files
- SPA content generated immediately
- Server starts successfully
- Full HTML generated in background
- Documentation accessible on first visit
Scenario 2: Manual HTML Generation
- User clicks "Publish HTML" button
- Loading toast appears
- Toast dismisses regardless of success/error
- Appropriate success/error message shown
- DocsPanel refreshes automatically
Scenario 3: Development Live-Reload
- WebSocket connection established
- Server broadcasts reload on HTML generation
- DocsPanel receives signal and refreshes
- No manual refresh required
Benefits
- Immediate Availability: HTML documentation ready on container startup
- Better UX: Proper toast feedback and auto-refresh
- Reliability: Robust error handling and fallback mechanisms
- Development Experience: Live-reload works seamlessly
- Non-blocking: Background processes don't delay container startup
Future Considerations
- Monitor server startup time to optimize background generation delay
- Consider adding progress indicators for long HTML generation processes
- Evaluate caching strategies for frequently accessed documentation
- Monitor WebSocket connection stability in production environments
Status: Complete
Generated: 2025-08-24 09:00 UTC