Skip to content

Commit 5d605c9

Browse files
committed
Enhance error handling with improved overlay cleanup and debug logging
1 parent 05c2dc2 commit 5d605c9

File tree

1 file changed

+51
-9
lines changed

1 file changed

+51
-9
lines changed

public/js/main.js

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -441,17 +441,53 @@ function initRouter() {
441441
console.log('Rendered content with component preservation and translations');
442442
},
443443
errorHandler: (path) => {
444+
console.log('Error handler called for path:', path);
445+
444446
// Use a more direct approach that bypasses the router's transition mechanism
445447
// This will be called immediately when the route is not found
446448
setTimeout(() => {
447449
// Get the root element
448450
const rootElement = document.getElementById('app');
451+
if (!rootElement) {
452+
console.error('Root element #app not found');
453+
return;
454+
}
455+
456+
console.log('Creating error page for path:', path);
457+
458+
// First, ensure all transition overlays are removed
459+
const cleanupOverlays = () => {
460+
// Remove any remaining transition overlays
461+
const overlays = document.querySelectorAll('.transition-overlay');
462+
console.log('Found transition overlays:', overlays.length);
463+
464+
overlays.forEach(overlay => {
465+
if (document.body.contains(overlay)) {
466+
console.log('Removing transition overlay:', overlay);
467+
document.body.removeChild(overlay);
468+
}
469+
});
470+
471+
// Also check for any elements with opacity or visibility styles that might be leftover
472+
document.querySelectorAll('[style*="opacity: 0"]').forEach(el => {
473+
if (el.classList.contains('transition-overlay') || el.style.position === 'absolute') {
474+
console.log('Removing hidden element with opacity 0:', el);
475+
if (el.parentNode) {
476+
el.parentNode.removeChild(el);
477+
}
478+
}
479+
});
480+
};
449481

450-
// Clear any existing content and overlays
482+
// Clean up overlays first
483+
cleanupOverlays();
484+
485+
// Clear any existing content
451486
rootElement.innerHTML = '';
452487

453488
// Create the error page content directly
454489
const errorContent = document.createElement('div');
490+
errorContent.className = 'error-page-container';
455491
errorContent.innerHTML = `
456492
<pf-header></pf-header>
457493
<div class="content-container" style="display: flex; justify-content: center; align-items: center; min-height: 60vh;">
@@ -467,17 +503,23 @@ function initRouter() {
467503
// Append the error content to the root element
468504
rootElement.appendChild(errorContent);
469505

506+
console.log('Error page content appended to DOM');
507+
470508
// Dispatch the transition-end event to ensure proper cleanup
471509
document.dispatchEvent(new CustomEvent('spa-transition-end'));
472510

473-
// Remove any remaining transition overlays
474-
const overlays = document.querySelectorAll('.transition-overlay');
475-
overlays.forEach(overlay => {
476-
if (document.body.contains(overlay)) {
477-
document.body.removeChild(overlay);
478-
}
479-
});
480-
}, 0);
511+
// Clean up overlays again after a short delay to catch any that might have been created during the transition
512+
setTimeout(cleanupOverlays, 100);
513+
514+
// Set up a safety interval to periodically check for and remove any overlays that might appear
515+
const safetyInterval = setInterval(cleanupOverlays, 500);
516+
517+
// Clear the safety interval after 3 seconds
518+
setTimeout(() => {
519+
clearInterval(safetyInterval);
520+
console.log('Safety interval cleared');
521+
}, 3000);
522+
}, 50); // Slight delay to ensure DOM is ready
481523

482524
// Return an empty string since we're handling the rendering directly
483525
return '';

0 commit comments

Comments
 (0)