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

Restrict ObjectCanon prototypes to {Array,Object}.prototype and null. #8260

Merged
merged 1 commit into from
May 18, 2021

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented May 18, 2021

As promised in #8222 (comment), a more general implementation of ObjectCanon is coming (after Apollo Client v3.4), so I think it would be wise to restrict the functionality of the current implementation to match what I have planned.

First, I want to reserve the isCanonical method to return true for anything that doesn't need to be (further) canonized, including primitive values. To that end, the isKnown method now returns true only for objects previously returned by canon.admit.

Second, the future implementation will allow full customization of canonization by object prototype, but will only canonize arrays and plain objects by default. To that end, I've restricted ObjectCanon canonization to objects whose prototypes are Array.prototype, Object.prototype, or null.

Comment on lines -129 to +130
case "[object Object]": {
case null:
case Object.prototype: {
Copy link
Member Author

Choose a reason for hiding this comment

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

The case "[object Object]" from before would have canonized most user-defined classes (the ones that don't redefine Symbol.toStringTag), which feels dangerous to me, because not every class can be canonized (canonization requires the ability to copy the object safely, for example). A more complete solution will allow defining appropriate canonization logic for specific object types/prototypes, in addition to the defaults.

As promised in #8222 (comment),
a more general implementation of ObjectCanon is coming, so I think we
should restrict the functionality of the current implementation to match
what we have planned.

First, I want to reserve the isCanonical method to return true for
anything that doesn't need to be (further) canonized, including
primitive values. To that end, the isKnown method now returns true only
for *objects* previously returned by canon.admit.

Second, the future implemenation will allow full customization of
canonization by object prototype, but will only canonize arrays and
plain objects by default. To that end, I've resricted ObjectCanon
canonization to objects whose prototypes are Array.prototype,
Object.prototype, or null.
@benjamn benjamn force-pushed the restrict-ObjectCanon-prototypes-for-now branch from ce247bf to f1cda57 Compare May 18, 2021 21:03
Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

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

Thanks @benjamn!

@benjamn benjamn merged commit 1241e2c into release-3.4 May 18, 2021
@benjamn benjamn deleted the restrict-ObjectCanon-prototypes-for-now branch May 18, 2021 23:16
@hwillson hwillson removed this from the MM-2021-06 milestone Jul 29, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants