fix: avoid project group order spread crash (#3675)

This commit is contained in:
Neil 2026-05-30 12:47:27 -07:00 committed by GitHub
parent 07b8d014bd
commit c8fd13120d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 4 deletions

View File

@ -16,6 +16,7 @@ import { join } from 'path'
import { tmpdir } from 'os'
import type {
PersistedState,
ProjectGroup,
Repo,
TerminalPaneLayoutNode,
TerminalTab,
@ -1518,6 +1519,35 @@ describe('Store', () => {
expect(store.getRepo('sibling')?.projectGroupId).toBe(sibling.id)
})
it('creates a project group when persisted group history is very large', async () => {
const projectGroups: ProjectGroup[] = Array.from({ length: 130_000 }, (_, index) => ({
id: `group-${index}`,
name: `Group ${index}`,
parentPath: null,
parentGroupId: null,
createdFrom: 'manual',
tabOrder: index,
isCollapsed: false,
color: null,
createdAt: index,
updatedAt: index
}))
writeDataFile({
schemaVersion: 1,
repos: [],
worktreeMeta: {},
settings: {},
ui: {},
githubCache: { pr: {}, issue: {} },
projectGroups
})
const store = await createStore()
const group = store.createProjectGroup({ name: 'New group', createdFrom: 'manual' })
expect(group.tabOrder).toBe(projectGroups.length)
})
it('sanitizes invalid project group updates before persisting a repo', async () => {
const store = await createStore()
const group = store.createProjectGroup({ name: 'Platform', createdFrom: 'manual' })

View File

@ -2127,10 +2127,11 @@ export class Store {
parentGroupId?: string | null
createdFrom: ProjectGroup['createdFrom']
}): ProjectGroup {
const maxOrder = Math.max(
-1,
...(this.state.projectGroups ?? []).map((group) => group.tabOrder)
)
let maxOrder = -1
// Why: persisted group lists can be large enough to exceed spread limits.
for (const existingGroup of this.state.projectGroups ?? []) {
maxOrder = Math.max(maxOrder, existingGroup.tabOrder)
}
const group = createProjectGroup({
...input,
tabOrder: maxOrder + 1