* Check if we're in a browser top-level window (not a worker, SSR, or iframe). * This helps avoid false positives in environments where multiple instances are legitimate.
()
| 5 | * This helps avoid false positives in environments where multiple instances are legitimate. |
| 6 | */ |
| 7 | function isBrowserTopWindow(): boolean { |
| 8 | const w = (globalThis as any).window |
| 9 | // Exclude workers and SSR-ish shims |
| 10 | if (!w || !(`document` in w)) return false |
| 11 | // Avoid triggering inside iframes (cross-origin iframes can throw) |
| 12 | try { |
| 13 | return w === w.top |
| 14 | } catch { |
| 15 | return true // If we can't access w.top due to cross-origin, assume we should check |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | // Detect duplicate @tanstack/db instances (dev-only, browser top-window only) |
| 20 | const DB_INSTANCE_MARKER = Symbol.for(`@tanstack/db/instance-marker`) |
no outgoing calls
no test coverage detected