Merge branch 'immediate-finds' into immediate-finds-modules-proxy

This commit is contained in:
Nuckyz 2024-06-21 22:55:20 -03:00
commit 700a442ee4
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

View file

@ -77,10 +77,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) => {
@ -109,7 +112,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);
} }
} }