| 1 |
import React from "react"; |
| 2 |
import ReactDOM from "react-dom/client"; |
| 3 |
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; |
| 4 |
import App from "./App"; |
| 5 |
import { ToastProvider } from "./components/ui/toast"; |
| 6 |
import { ErrorBoundary } from "./components/ErrorBoundary"; |
| 7 |
import "./css/index.css"; |
| 8 |
|
| 9 |
// Create React Query client with proper configuration |
| 10 |
let queryClient: QueryClient; |
| 11 |
|
| 12 |
try { |
| 13 |
queryClient = new QueryClient({ |
| 14 |
defaultOptions: { |
| 15 |
queries: { |
| 16 |
refetchOnWindowFocus: false, |
| 17 |
retry: 1, |
| 18 |
staleTime: 5 * 60 * 1000, // 5 minutes |
| 19 |
}, |
| 20 |
}, |
| 21 |
}); |
| 22 |
} catch (error) { |
| 23 |
console.error("Error initializing QueryClient:", error); |
| 24 |
// Fallback: create with minimal config |
| 25 |
queryClient = new QueryClient(); |
| 26 |
} |
| 27 |
|
| 28 |
// When a lazily-loaded page chunk fails to load — almost always because a new |
| 29 |
// build replaced the content-hashed chunk while this tab still holds an old |
| 30 |
// reference — Vite fires `vite:preloadError`. Reload once to fetch the current |
| 31 |
// bundle instead of crashing with "Failed to fetch dynamically imported module". |
| 32 |
// The time-based guard prevents a reload loop if the chunk is genuinely missing. |
| 33 |
window.addEventListener("vite:preloadError", () => { |
| 34 |
const KEY = "yatra-last-chunk-reload"; |
| 35 |
const last = Number(window.sessionStorage.getItem(KEY) || 0); |
| 36 |
const now = Date.now(); |
| 37 |
if (now - last > 10000) { |
| 38 |
window.sessionStorage.setItem(KEY, String(now)); |
| 39 |
window.location.reload(); |
| 40 |
} |
| 41 |
}); |
| 42 |
|
| 43 |
// Get mount point |
| 44 |
const rootElement = document.getElementById("yatra-app-root"); |
| 45 |
|
| 46 |
if (rootElement) { |
| 47 |
// Tell browser translation engines (Google Translate, Edge, etc.) not to |
| 48 |
// rewrite React-managed text nodes. When they do, the DOM no longer matches |
| 49 |
// React's fiber tree and unmounting a subtree throws |
| 50 |
// "Failed to execute 'removeChild' on 'Node'". Opting out here keeps |
| 51 |
// reconciliation safe without changing any behaviour. |
| 52 |
rootElement.setAttribute("translate", "no"); |
| 53 |
rootElement.classList.add("notranslate"); |
| 54 |
|
| 55 |
try { |
| 56 |
const root = ReactDOM.createRoot(rootElement); |
| 57 |
|
| 58 |
root.render( |
| 59 |
<React.StrictMode> |
| 60 |
<QueryClientProvider client={queryClient}> |
| 61 |
<ToastProvider> |
| 62 |
<ErrorBoundary> |
| 63 |
<App /> |
| 64 |
</ErrorBoundary> |
| 65 |
</ToastProvider> |
| 66 |
</QueryClientProvider> |
| 67 |
</React.StrictMode>, |
| 68 |
); |
| 69 |
} catch (error) { |
| 70 |
console.error("Error rendering React app:", error); |
| 71 |
rootElement.innerHTML = |
| 72 |
'<div style="padding: 40px; text-align: center;"><h2>Error loading Yatra Admin</h2><p>Please refresh the page or contact support.</p></div>'; |
| 73 |
} |
| 74 |
} |
| 75 |
|