// Safe global JSON.stringify patch to handle circular references (e.g. from third-party scripts or dev preview selection tools)
const originalStringify = JSON.stringify;
JSON.stringify = function (value: any, replacer?: any, space?: any) {
  try {
    return originalStringify(value, replacer, space);
  } catch (err: any) {
    if (err instanceof TypeError && (err.message.includes("circular") || err.message.includes("Circular"))) {
      const seen = new WeakSet();
      return originalStringify(value, function (key, val) {
        if (typeof val === "object" && val !== null) {
          if (seen.has(val)) {
            return "[Circular]";
          }
          seen.add(val);
          if (typeof Node !== "undefined" && val instanceof Node) {
            return `[DOMNode: ${val.nodeName}]`;
          }
        }
        if (typeof replacer === "function") {
          return replacer(key, val);
        } else if (Array.isArray(replacer)) {
          if (key === "" || replacer.includes(key)) {
            return val;
          }
          return undefined;
        }
        return val;
      }, space);
    }
    throw err;
  }
};

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>,
);
