| 1 |
import React from 'react'; |
| 2 |
import { createRoot } from 'react-dom/client'; |
| 3 |
import App from './App'; |
| 4 |
import './styles/main.css'; |
| 5 |
|
| 6 |
// Module-level root reference to prevent duplicate createRoot calls |
| 7 |
let root = null; |
| 8 |
|
| 9 |
// Skip mounting inside nested iframes (e.g., Gutenberg block canvas, |
| 10 |
// SureForms shortcode previews that load the frontend in an iframe). |
| 11 |
const isInIframe = (() => { |
| 12 |
try { return window.self !== window.top; } catch { return true; } |
| 13 |
})(); |
| 14 |
|
| 15 |
// Mount React app |
| 16 |
const container = isInIframe ? null : document.getElementById('chat-assistant-root'); |
| 17 |
|
| 18 |
if (container && !root) { |
| 19 |
root = createRoot(container); |
| 20 |
root.render( |
| 21 |
<React.StrictMode> |
| 22 |
<App /> |
| 23 |
</React.StrictMode> |
| 24 |
); |
| 25 |
} |
| 26 |
|