Skip to content

Commit 0213eee

Browse files
authored
fix(core): domGetter为string且dom树下没有对应的节点,会导致无限递归(#607) (#609)
fix(core): domGetter为string且dom树下没有对应的节点,会导致无限递归(#607) (#609)
1 parent 009b348 commit 0213eee

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/utils/src/container.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,18 @@ export function createAppContainer(appInfo: interfaces.AppInfo) {
5656
/**
5757
* Wait for the specified dom ready tool method
5858
*/
59-
function waitElementReady(selector, callback) {
59+
function waitElementReady(selector, callback, leftTime) {
60+
const timeInterval = 50;
6061
const elem = document.querySelector(selector);
6162

62-
if (elem !== null) {
63+
if (elem !== null || leftTime <= 0) {
6364
callback(elem);
6465
return;
6566
}
6667

6768
setTimeout(function () {
68-
waitElementReady(selector, callback);
69-
}, 50);
69+
waitElementReady(selector, callback, leftTime - timeInterval);
70+
}, timeInterval);
7071
}
7172

7273
function delay(duration) {
@@ -77,9 +78,13 @@ function delay(duration) {
7778

7879
function waitElement(selector, timeout = 3000) {
7980
const waitPromise = new Promise(function (resolve) {
80-
waitElementReady(selector, function (elem: Element) {
81-
return resolve(elem);
82-
});
81+
waitElementReady(
82+
selector,
83+
function (elem: Element) {
84+
return resolve(elem);
85+
},
86+
timeout
87+
);
8388
});
8489
return Promise.race([delay(timeout), waitPromise]);
8590
}

0 commit comments

Comments
 (0)