domGetter为string且dom树下没有对应的节点,会导致无限递归。
workkk98 opened this issue · comments
Describe the bug
具体原因我们可以直接看packages/utils/src/containers中的代码。
/**
* Wait for the specified dom ready tool method
*/
function waitElementReady(selector, callback) {
const elem = document.querySelector(selector);
if (elem !== null) {
callback(elem);
return;
}
setTimeout(function () {
waitElementReady(selector, callback);
}, 50);
}
function delay(duration) {
return new Promise(function (resolve) {
setTimeout(resolve, duration);
});
}
function waitElement(selector, timeout = 3000) {
const waitPromise = new Promise(function (resolve) {
waitElementReady(selector, function (elem: Element) {
return resolve(elem);
});
});
return Promise.race([delay(timeout), waitPromise]);
}
waitElementReady会在找不到节点后继续递归自己。我理解这里的设计应该是timeout这个阈值过后,就应当结束掉递归。因为Promise.race已经返回了delay的结果,继续递归也没有任何意义。
Reproduction
https://stackblitz.com/edit/garfish-demo-5vdvgl?file=main%2Fsrc%2FApp.js
Used Package Manager
npm
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 7.17.0 - /usr/local/bin/npm
Validations
- Read the docs.
- Read the common issues list.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Garfish issue and not a framework-specific issue.
- The provided reproduction is a minimal reproducible example of the bug.
这里确实有这个问题,有空的话欢迎 pr 👏
这里确实有这个问题,有空的话欢迎 pr 👏
看下是否能合入呢?
#609