From 97990163b858882b6578ed9c64ecccca0c676fc4 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 30 May 2026 06:24:07 -0700 Subject: [PATCH] fix: collect wide project group subtrees (#3692) --- src/shared/project-groups.test.ts | 16 ++++++++++++++++ src/shared/project-groups.ts | 13 ++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/shared/project-groups.test.ts b/src/shared/project-groups.test.ts index 574d17503..a64003b83 100644 --- a/src/shared/project-groups.test.ts +++ b/src/shared/project-groups.test.ts @@ -112,4 +112,20 @@ describe('project-groups', () => { ].sort() ).toEqual(['child', 'grandchild', 'root']) }) + + it('collects wide descendant groups without overflowing argument limits', () => { + const groups = [ + { id: 'root', parentGroupId: null }, + ...Array.from({ length: 130_000 }, (_, index) => ({ + id: `child-${index}`, + parentGroupId: 'root' + })) + ] + + const subtreeIds = getProjectGroupSubtreeIds(groups, 'root') + + expect(subtreeIds.size).toBe(130_001) + expect(subtreeIds.has('root')).toBe(true) + expect(subtreeIds.has('child-129999')).toBe(true) + }) }) diff --git a/src/shared/project-groups.ts b/src/shared/project-groups.ts index f1bb76b88..4a208c685 100644 --- a/src/shared/project-groups.ts +++ b/src/shared/project-groups.ts @@ -105,10 +105,9 @@ export function getProjectGroupSubtreeIds( if (!group.parentGroupId) { continue } - childGroupsByParentId.set(group.parentGroupId, [ - ...(childGroupsByParentId.get(group.parentGroupId) ?? []), - group.id - ]) + const children = childGroupsByParentId.get(group.parentGroupId) ?? [] + children.push(group.id) + childGroupsByParentId.set(group.parentGroupId, children) } const subtreeIds = new Set() @@ -119,7 +118,11 @@ export function getProjectGroupSubtreeIds( continue } subtreeIds.add(groupId) - pending.push(...(childGroupsByParentId.get(groupId) ?? [])) + // Why: imported project-group trees can be very wide; `push(...children)` + // can exceed V8's argument limit while collecting descendants. + for (const childGroupId of childGroupsByParentId.get(groupId) ?? []) { + pending.push(childGroupId) + } } return subtreeIds }