// Ensure circular structures (DOM nodes with React Fiber attachments) are safe for serialization
const originalStringify = JSON.stringify;
JSON.stringify = function (value: any, replacer?: any, space?: any) {
  const seen = new WeakSet();
  function safeReplacer(this: any, key: string, val: any) {
    if (typeof val === 'object' && val !== null) {
      if (val instanceof Node || (typeof HTMLElement !== 'undefined' && val instanceof HTMLElement) || val === window) {
        return {
          nodeName: val.nodeName || 'WINDOW',
          id: val.id || undefined,
          className: typeof val.className === 'string' ? val.className : undefined,
        };
      }
      if (seen.has(val)) {
        return '[Circular]';
      }
      seen.add(val);
    }
    if (typeof replacer === 'function') {
      return replacer.call(this, key, val);
    }
    return val;
  }
  try {
    return originalStringify.call(this, value, safeReplacer, space);
  } catch {
    return '"{}"';
  }
};

import {StrictMode} from 'react';
import {createRoot} from 'react-dom/client';
import App from './App.tsx';
import './index.css';

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <App />
  </StrictMode>,
);
