Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

597 B
Raw Blame
/* Deep-clone that tolerates reactive proxies. `structuredClone` throws
 * `DataCloneError` on Vue's proxies in some browsers (Firefox); JSON
 * round-trip is a safe fallback for plain JSON-shaped data. */
import ErrorHandler from '@/utils/logging/ErrorHandler';

export default function safeClone(val, fallback = null) {
  if (val == null) return fallback;
  try {
    return structuredClone(val);
  } catch {
    try {
      return JSON.parse(JSON.stringify(val));
    } catch (e) {
      ErrorHandler('safeClone failed', e);
      return fallback ?? (Array.isArray(val) ? [] : {});
    }
  }
}