Skip to content

Commit 7170983

Browse files
committed
fix(app): duplicate session loads
1 parent b05d88a commit 7170983

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

packages/app/src/context/global-sync.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ function createGlobalSync() {
133133
const children: Record<string, [Store<State>, SetStoreFunction<State>]> = {}
134134
const booting = new Map<string, Promise<void>>()
135135
const sessionLoads = new Map<string, Promise<void>>()
136+
const sessionMeta = new Map<string, { limit: number }>()
136137

137138
function ensureChild(directory: string) {
138139
if (!directory) console.error("No directory provided")
@@ -192,7 +193,8 @@ function createGlobalSync() {
192193
if (pending) return pending
193194

194195
const [store, setStore] = child(directory, { bootstrap: false })
195-
const limit = store.limit
196+
const meta = sessionMeta.get(directory)
197+
if (meta && meta.limit >= store.limit) return
196198

197199
const promise = globalSDK.client.session
198200
.list({ directory, roots: true })
@@ -203,9 +205,15 @@ function createGlobalSync() {
203205
.slice()
204206
.sort((a, b) => a.id.localeCompare(b.id))
205207

208+
// Read the current limit at resolve-time so callers that bump the limit while
209+
// a request is in-flight still get the expanded result.
210+
const limit = store.limit
211+
206212
const sandboxWorkspace = globalStore.project.some((p) => (p.sandboxes ?? []).includes(directory))
207213
if (sandboxWorkspace) {
214+
setStore("sessionTotal", nonArchived.length)
208215
setStore("session", reconcile(nonArchived, { key: "id" }))
216+
sessionMeta.set(directory, { limit })
209217
return
210218
}
211219

@@ -219,6 +227,7 @@ function createGlobalSync() {
219227
// Store total session count (used for "load more" pagination)
220228
setStore("sessionTotal", nonArchived.length)
221229
setStore("session", reconcile(sessions, { key: "id" }))
230+
sessionMeta.set(directory, { limit })
222231
})
223232
.catch((err) => {
224233
console.error("Failed to load sessions", err)

0 commit comments

Comments
 (0)