// src/main.jsx - Simplified and Fixed import { StrictMode } from 'react'; import { createRoot } from 'react-dom/client'; import './index.css'; import AppWithErrorBoundary from './components/AppWithErrorBoundary.jsx'; import BrowserWarning from './components/BrowserWarning.jsx'; import { initializeBrowserSupport, loadPolyfills } from './utils/browserCompatibility.js'; // Performance monitoring if (typeof performance !== 'undefined' && performance.mark) { performance.mark('app-init-start'); } // Main initialization function async function initializeApp() { try { console.log('🚀 Starting application initialization...'); // Check browser support first const { support, browserInfo } = initializeBrowserSupport(); // Load polyfills for unsupported browsers if (!support.isSupported) { console.log('⚠️ Loading polyfills for browser compatibility...'); try { await loadPolyfills(); } catch (polyfillError) { console.warn('Failed to load some polyfills:', polyfillError); } } // Get root element const rootElement = document.getElementById('root'); if (!rootElement) { throw new Error('Root element #root not found in DOM'); } // Create React root const root = createRoot(rootElement); // Show browser warning if there are compatibility issues if (!support.isSupported && support.unsupportedFeatures.length > 0) { console.warn('🌐 Browser compatibility issues detected:', support.unsupportedFeatures); // Create warning overlay const warningDiv = document.createElement('div'); warningDiv.id = 'browser-warning'; warningDiv.className = 'browser-warning-overlay'; document.body.appendChild(warningDiv); const warningRoot = createRoot(warningDiv); warningRoot.render( { // Remove warning overlay const overlay = document.getElementById('browser-warning'); if (overlay) { overlay.remove(); } console.log('User chose to continue with unsupported browser'); }} /> ); } // Render main application root.render( ); console.log('✅ Application initialized successfully'); // Performance measurement if (typeof performance !== 'undefined' && performance.mark && performance.measure) { performance.mark('app-init-end'); performance.measure('app-init-duration', 'app-init-start', 'app-init-end'); const measures = performance.getEntriesByType('measure'); const initMeasure = measures.find(m => m.name === 'app-init-duration'); if (initMeasure) { console.log(`⏱️ App initialization completed in ${Math.round(initMeasure.duration)}ms`); } } } catch (error) { console.error('❌ Critical error during application initialization:', error); // Show fallback error UI (this handles initialization errors, not React rendering errors) showFallbackErrorUI(error); } } // Fallback error UI for initialization failures (not React rendering errors) function showFallbackErrorUI(error) { const errorHTML = `

Application Failed to Load

We're sorry, but Resume Tools encountered an error during startup. This could be due to network issues, browser compatibility, or a temporary server problem.

Technical Details:

${error.message}

If this problem persists, try clearing your browser cache or using a different browser.

`; // Replace entire body content with error UI document.body.innerHTML = errorHTML; } // Global error handlers for unhandled errors window.addEventListener('error', (event) => { console.error('🚨 Global JavaScript Error:', { message: event.message || 'Unknown error', filename: event.filename || 'Unknown file', lineno: event.lineno || 0, colno: event.colno || 0, error: event.error ? { name: event.error.name, message: event.error.message, stack: event.error.stack?.substring(0, 500) // Limit stack trace length } : null, timestamp: new Date().toISOString(), userAgent: navigator.userAgent.substring(0, 100) // Limit user agent length }); }); window.addEventListener('unhandledrejection', (event) => { console.error('🚨 Unhandled Promise Rejection:', { reason: event.reason ? { name: event.reason.name || 'UnknownError', message: event.reason.message || event.reason.toString(), stack: event.reason.stack?.substring(0, 500) // Limit stack trace length } : String(event.reason), timestamp: new Date().toISOString() }); // Prevent default browser behavior event.preventDefault(); }); // Initialize the application initializeApp();