fix issues related to nested proxyInner

This commit is contained in:
Nuckyz 2024-06-21 22:54:08 -03:00
parent 570137040c
commit dd3904badd
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

View file

@ -80,10 +80,13 @@ export function proxyInner<T = AnyObject>(
}
// If we're still in the same tick, it means the proxy was immediately used.
// thus, we proxy the get access to make things like destructuring work as expected
// meow here will also be a proxy
// `const { meow } = findByProps("meow");`
if (!isChild && isSameTick) {
// And, if the inner value is still nullish, it means the proxy was used before setInnerValue was called.
// So, proxy the get access to make things like destructuring work as expected.
// We dont need to proxy if the inner value is available, and recursiveSetInnerValue won't ever be called anyways,
// because the top setInnerValue was called before we proxied the get access
// example here will also be a proxy:
// `const { example } = findByProps("example");`
if (isSameTick && proxyDummy[SYM_PROXY_INNER_VALUE] == null && !isChild) {
const [recursiveProxy, recursiveSetInnerValue] = proxyInner(errMsg, primitiveErrMsg, true);
recursiveSetInnerValues.push((innerValue: T) => {
@ -112,7 +115,9 @@ export function proxyInner<T = AnyObject>(
proxyDummy[SYM_PROXY_INNER_VALUE] = innerValue;
recursiveSetInnerValues.forEach(setInnerValue => setInnerValue(innerValue));
if (typeof innerValue === "function") {
// Avoid binding toString if the inner value is null.
// This can happen if we are setting the inner value as another instance of proxyInner, which will cause that proxy to instantly evaluate and throw an error
if (typeof innerValue === "function" && innerValue[SYM_PROXY_INNER_GET] == null) {
proxy.toString = innerValue.toString.bind(innerValue);
}
}