fix issues related to nested proxyInner
This commit is contained in:
parent
570137040c
commit
dd3904badd
|
@ -80,10 +80,13 @@ export function proxyInner<T = AnyObject>(
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're still in the same tick, it means the proxy was immediately used.
|
// 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
|
// And, if the inner value is still nullish, it means the proxy was used before setInnerValue was called.
|
||||||
// meow here will also be a proxy
|
// So, proxy the get access to make things like destructuring work as expected.
|
||||||
// `const { meow } = findByProps("meow");`
|
// We dont need to proxy if the inner value is available, and recursiveSetInnerValue won't ever be called anyways,
|
||||||
if (!isChild && isSameTick) {
|
// 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);
|
const [recursiveProxy, recursiveSetInnerValue] = proxyInner(errMsg, primitiveErrMsg, true);
|
||||||
|
|
||||||
recursiveSetInnerValues.push((innerValue: T) => {
|
recursiveSetInnerValues.push((innerValue: T) => {
|
||||||
|
@ -112,7 +115,9 @@ export function proxyInner<T = AnyObject>(
|
||||||
proxyDummy[SYM_PROXY_INNER_VALUE] = innerValue;
|
proxyDummy[SYM_PROXY_INNER_VALUE] = innerValue;
|
||||||
recursiveSetInnerValues.forEach(setInnerValue => setInnerValue(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);
|
proxy.toString = innerValue.toString.bind(innerValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue