Skip to content
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

Fix #2871 toJS throws with configure({ useProxies: "ifavailable" }) #2873

Merged
merged 3 commits into from
Apr 3, 2021
Merged

Fix #2871 toJS throws with configure({ useProxies: "ifavailable" }) #2873

merged 3 commits into from
Apr 3, 2021

Conversation

urugator
Copy link
Collaborator

@urugator urugator commented Apr 1, 2021

Fixes: #2871 in BC manner.

We may want to reconsider which kind fo keys toJS returns.

@changeset-bot
Copy link

changeset-bot bot commented Apr 1, 2021

🦋 Changeset detected

Latest commit: 97523ba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mobx Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@mweststrate mweststrate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment, I think the proposed fix is incorrect; even in ES5 mode, toJS should still be reacting to key addition / removals, and I don't think that is the case with the current solution? (We might be missing an explicit test for that)

const res = cache(__alreadySeen, source, {})
getPlainObjectKeys(source).forEach((key: any) => {
res[key] = toJSHelper(source[key], __alreadySeen)
;((source as any) as IIsObservableObject)[$mobx].ownKeys_().forEach((key: any) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the fix here is incorrect; we should use keys(source) as basis for the loop, and not use getPlainObjectKeys, to make sure that toJS will track key additions, even when it is used in ES5 mode. There are probably subtle differences between keys and getPlainObjectKeys that might need to be addressed, but we should use keys as basis, or keep it as implemented here, but make sure a read to the keys atom is registered.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adm.ownKeys_ handles the subscription to keys atom the same way as keys(object). We simply don't have ownKeys_ exposed via object-api so I call it directly on administration.

Copy link
Collaborator Author

@urugator urugator Apr 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify further, there is no longer any interesting logic (like keyAtom subscriptions) in object-api or in proxy handler. They simply delegate to adm and everything is done there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok great, that should work!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving the merging up to you, in case you want to merge the open PR's in a specific order :)

@urugator urugator merged commit 6b324ed into mobxjs:main Apr 3, 2021
@github-actions github-actions bot mentioned this pull request Apr 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using toJS inside observer component crashes in ES5 mode
2 participants