MCPcopy Create free account
hub / github.com/TanStack/db / isBrowserTopWindow

Function isBrowserTopWindow

packages/db/src/duplicate-instance-check.ts:7–17  ·  view source on GitHub ↗

* 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.

()

Source from the content-addressed store, hash-verified

5 * This helps avoid false positives in environments where multiple instances are legitimate.
6 */
7function 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)
20const DB_INSTANCE_MARKER = Symbol.for(`@tanstack/db/instance-marker`)

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected