benjamn / wryware

A collection of packages that are probably a little too clever. Use at your own wrisk.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

equal Hard Erroring on Proxies

Tmktahu opened this issue · comments

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]')

@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.

@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