mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
fix(tui): add linear search fallback for session update/delete sync
Binary.search may fail to find sessions when the store array order differs from expected sort order. This adds a linear search fallback to ensure session updates (rename) and deletes are properly synced to the UI. Fixes #5494 Fixes #3779
This commit is contained in:
parent
f8bca50f00
commit
fc36599f79
1 changed files with 18 additions and 0 deletions
|
|
@ -148,6 +148,17 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
|||
draft.splice(result.index, 1)
|
||||
}),
|
||||
)
|
||||
break
|
||||
}
|
||||
// Linear search fallback for sort order edge cases
|
||||
const linearIndex = store.session.findIndex((s) => s.id === event.properties.info.id)
|
||||
if (linearIndex !== -1) {
|
||||
setStore(
|
||||
"session",
|
||||
produce((draft) => {
|
||||
draft.splice(linearIndex, 1)
|
||||
}),
|
||||
)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
|
@ -157,6 +168,13 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
|||
setStore("session", result.index, reconcile(event.properties.info))
|
||||
break
|
||||
}
|
||||
// Linear search fallback for sort order edge cases
|
||||
const linearIndex = store.session.findIndex((s) => s.id === event.properties.info.id)
|
||||
if (linearIndex !== -1) {
|
||||
setStore("session", linearIndex, reconcile(event.properties.info))
|
||||
break
|
||||
}
|
||||
// Not found, insert at binary search position
|
||||
setStore(
|
||||
"session",
|
||||
produce((draft) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue