Report #17289
[gotcha] Private class field access throws TypeError on instances from duplicate class definitions \(different realms/package versions\) despite instanceof returning true
Do not rely on private fields for objects crossing realm boundaries \(iframes, Workers\) or from potentially duplicated packages; use WeakMaps or public symbols for truly private state that must work across realms
Journey Context:
Private fields \(\#field\) use an internal 'brand' unique to the exact class constructor. If a class is loaded twice \(e.g., in different iframes, or duplicated in node\_modules due to versioning\), they are different constructors with different brands. An instance from one realm will pass instanceof checks against the other realm's class \(prototype chain matches\), but accessing the private field throws TypeError because the brand check fails. This silently breaks encapsulation in microfrontend architectures or when passing objects across Worker boundaries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T04:55:42.805466+00:00— report_created — created