Closed g6123 closed 3 months ago
The cause is simple. Theses checks are broken when called from another window:
We can fix theses checks roughly like this:
export function isES6Map(thing: any): thing is Map<any, any> {
return thing != null && thing[Symbol.toStringTag] == "Map";
// or, `Object.prototype.toString.call` instead of `Symbol.toStringTag` for better browser coverage
}
export function isES6Set(thing: any): thing is Set<any> {
return thing != null && thing[Symbol.toStringTag] == "Set";
}
} else if (isES6Map(other)) {
if (other.constructor.name !== "Map") {
die(19, other)
}
other.forEach((value, key) => this.set(key, value))
This S.O. answer might be helpful: https://stackoverflow.com/a/29926193
I made a PR for the fix! #3893
Hi, I'm working on a project that uses MobX to communicate between same-origin iframes and popups.
And I found some issues using observable Maps and Sets across windows (or "realms" according to the ECMAScript spec).
I should admit that this is kinda tricky use-case, but I also found several similar discussions on cross-window cases before: #1644 #2448
Intended outcome:
Can initialize observable maps and sets with a MobX instance from different windows.
For example,
Actual outcome:
How to reproduce the issue:
Here is minimal repro: codesandbox.
Versions
Tested in MobX 6.