From ec907627b862d66e4cc24bc8062b4123eb976529 Mon Sep 17 00:00:00 2001 From: Devon Schneider Date: Sat, 8 Oct 2022 07:35:21 -0600 Subject: Use a conditional while loop for when the scroll root is not found. (#212) * Changed back to a while loop for grabbing the scroll root\nAs recursive function exits before it hits 30 iterations in testing. * Changed so if recursive limit is hit, it returns null instead of attempting to continue. * Added log messages regarding recursion limits, as well as fixed recursion tracking. * Removed errant return remaining from scroll root check. --- frontend/src/tabs-hook.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/frontend/src/tabs-hook.ts b/frontend/src/tabs-hook.ts index ac3dac39..e75e043d 100644 --- a/frontend/src/tabs-hook.ts +++ b/frontend/src/tabs-hook.ts @@ -49,23 +49,29 @@ class TabsHook extends Logger { let scrollRoot: any; async function findScrollRoot(currentNode: any, iters: number): Promise { if (iters >= 30) { - await sleep(5000); - return await findScrollRoot(tree, 0); + self.error( + 'Scroll root was not found before hitting the recursion limit, a developer will need to increase the limit.', + ); + return null; } currentNode = currentNode?.child; - if (currentNode?.type?.prototype?.RemoveSmartScrollContainer) return currentNode; + if (currentNode?.type?.prototype?.RemoveSmartScrollContainer) { + self.log(`Scroll root was found in ${iters} recursion cycles`); + return currentNode; + } if (!currentNode) return null; if (currentNode.sibling) { - let node = await findScrollRoot(currentNode.sibling, iters++); + let node = await findScrollRoot(currentNode.sibling, iters + 1); if (node !== null) return node; } - return await findScrollRoot(currentNode, iters++); + return await findScrollRoot(currentNode, iters + 1); } (async () => { scrollRoot = await findScrollRoot(tree, 0); - if (!scrollRoot) { - this.error('Failed to find scroll root node!'); - return; + while (!scrollRoot) { + this.log('Failed to find scroll root node, reattempting in 5 seconds'); + await sleep(5000); + scrollRoot = await findScrollRoot(tree, 0); } let newQA: any; let newQATabRenderer: any; -- cgit v1.2.3