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

equal Hard Erroring on Proxies #452

Open
Tmktahu opened this issue Feb 3, 2023 · 2 comments
Open

equal Hard Erroring on Proxies #452

Tmktahu opened this issue Feb 3, 2023 · 2 comments

Comments

@Tmktahu
Copy link

Tmktahu commented Feb 3, 2023

I discovered this from Apollo Client.

In some cases, the parameters passed to the equal method are wrapped in Proxies. If the wrapped value is an object with a nested array, it hard errors on this specific line with the following error:

TypeError: 'get' on proxy: property 'nestedArrayPropertyName' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected '[object Array]' but got '[object Array]')

@benjamn
Copy link
Owner

benjamn commented Feb 13, 2023

@Tmktahu Thanks for filing this issue. If you have the time, it would be great if you could open a PR with a failing test case here (without involving Apollo Client).

I'm hoping to understand what specific kind of Proxy usage isn't working, because I can imagine a few different possible scenarios. For example, I wonder if the @wry/equality code is mistakenly iterating over the properties of a Proxy object that should only be compared with === (that is, deep equality checking does not make sense for this object)… or maybe the Proxy is attempting to pass as a plain JS object, so it makes sense to compare its properties for deep equality, but one of the Proxy's properties (nestedArrayPropertyName?) is misbehaving in some edge case? Different remedies apply.

@Tmktahu
Copy link
Author

Tmktahu commented Feb 15, 2023

@benjamn it's tricky to make a failing test since I'm not 100% sure what specifically about the Proxies are causing it to fail. I've made a PR that I think showcases the problem case.

After fiddling around, the problem seems to stem from the Proxy's get function. Despite the objects appearing identical via the toStr up in the test error handler, equal fails. But I have no way of examining the get functions that are triggering the problem in Apollo Client... so I'm not sure what specifically about the get function is causing the issue.

Hopefully the case I outlined here is the one that is happening in Apollo Client.
#459

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

No branches or pull requests

2 participants