From d8ab094a45b9629ac664478d95f9aea0054bf17f Mon Sep 17 00:00:00 2001 From: Tony Murphy Date: Tue, 7 Oct 2025 08:21:13 -0700 Subject: [PATCH] LoadingGroups: Remove recursions from function --- .../runtime-utils/src/snapshotUtils.ts | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/runtime/runtime-utils/src/snapshotUtils.ts b/packages/runtime/runtime-utils/src/snapshotUtils.ts index 23d31d13a48a..eb2cd942bee2 100644 --- a/packages/runtime/runtime-utils/src/snapshotUtils.ts +++ b/packages/runtime/runtime-utils/src/snapshotUtils.ts @@ -16,23 +16,24 @@ export function isSnapshotFetchRequiredForLoadingGroupId( snapshotTree: ISnapshotTree, blobContents: Map, ): boolean { - for (const [_, id] of Object.entries(snapshotTree.blobs)) { - if (!blobContents.has(id)) { - return true; - } - } - for (const [_, childTree] of Object.entries(snapshotTree.trees)) { - // Only evaluate childTree if it does not have a loading groupId because if the childTree has a loading - // groupId then it will be evaluated whether we want to fetch blobs for that childTree or not when - // that particular childTree is getting realized. Now we just want to check for blobs which belongs to - // tree with current loading groupId. Note: Child with no loading groupId, will fall under parent with - // a loading groupId as it does not have its own loading groupId. - if (childTree.groupId === undefined) { - const value = isSnapshotFetchRequiredForLoadingGroupId(childTree, blobContents); - if (value) { + const trees = [snapshotTree]; + let tree: ISnapshotTree | undefined; + while ((tree = trees.pop()) !== undefined) { + for (const [_, id] of Object.entries(tree.blobs)) { + if (!blobContents.has(id)) { return true; } } + for (const [_, childTree] of Object.entries(tree.trees)) { + // Only evaluate childTree if it does not have a loading groupId because if the childTree has a loading + // groupId then it will be evaluated whether we want to fetch blobs for that childTree or not when + // that particular childTree is getting realized. Now we just want to check for blobs which belongs to + // tree with current loading groupId. Note: Child with no loading groupId, will fall under parent with + // a loading groupId as it does not have its own loading groupId. + if (childTree.groupId === undefined) { + trees.push(childTree); + } + } } return false; }