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 }