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:
Federico Crespo 2025-12-14 07:36:47 -03:00
parent f8bca50f00
commit fc36599f79

View file

@ -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) => {