-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot initialize observable Map/Sets from another window #3892
Comments
The cause is simple. Theses checks are broken when called from another window: mobx/packages/mobx/src/utils/utils.ts Lines 143 to 149 in a73710c
mobx/packages/mobx/src/types/observablemap.ts Lines 353 to 357 in a73710c
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.
The text was updated successfully, but these errors were encountered: