fix: avoid project group order spread crash (#3675)
This commit is contained in:
parent
07b8d014bd
commit
c8fd13120d
|
|
@ -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' })
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue