diff options
Diffstat (limited to 'frontend/src/tabs-hook.ts')
| -rw-r--r-- | frontend/src/tabs-hook.ts | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/frontend/src/tabs-hook.ts b/frontend/src/tabs-hook.ts index be413de0..e75e043d 100644 --- a/frontend/src/tabs-hook.ts +++ b/frontend/src/tabs-hook.ts @@ -47,18 +47,31 @@ class TabsHook extends Logger { const self = this; const tree = (document.getElementById('root') as any)._reactRootContainer._internalRoot.current; let scrollRoot: any; - let currentNode = tree; + async function findScrollRoot(currentNode: any, iters: number): Promise<any> { + if (iters >= 30) { + 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) { + 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 + 1); + if (node !== null) return node; + } + return await findScrollRoot(currentNode, iters + 1); + } (async () => { - let iters = 0; + scrollRoot = await findScrollRoot(tree, 0); while (!scrollRoot) { - iters++; - currentNode = currentNode?.child; - if (iters >= 30 || !currentNode) { - iters = 0; - currentNode = tree; - await sleep(5000); - } - if (currentNode?.type?.prototype?.RemoveSmartScrollContainer) scrollRoot = currentNode; + 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; @@ -101,6 +114,7 @@ class TabsHook extends Logger { }); this.cNode = scrollRoot; this.cNode.stateNode.forceUpdate(); + this.log('Finished initial injection'); })(); } |
