tidy normalized store hydration

This commit is contained in:
Shantur Rathore
2025-11-26 15:59:24 +00:00
parent 4e0e5dcdca
commit 3db9b0f673
2 changed files with 16 additions and 21 deletions

View File

@@ -1,3 +1,4 @@
import { batch } from "solid-js"
import { createStore, produce, reconcile } from "solid-js/store" import { createStore, produce, reconcile } from "solid-js/store"
import type { SetStoreFunction } from "solid-js/store" import type { SetStoreFunction } from "solid-js/store"
import type { ClientPart, MessageInfo } from "../../types/message" import type { ClientPart, MessageInfo } from "../../types/message"
@@ -361,22 +362,24 @@ export function createInstanceMessageStore(instanceId: string): InstanceMessageS
} }
} }
setState("messages", (prev) => ({ ...prev, ...nextMessages })) batch(() => {
setState("messageInfoVersion", (prev) => ({ ...prev, ...nextMessageInfoVersion })) setState("messages", () => nextMessages)
setState("pendingParts", () => nextPendingParts) setState("messageInfoVersion", () => nextMessageInfoVersion)
setState("permissions", "byMessage", (prev) => ({ ...prev, ...nextPermissionsByMessage })) setState("pendingParts", () => nextPendingParts)
setState("permissions", "byMessage", () => nextPermissionsByMessage)
if (usageState) { if (usageState) {
setState("usage", sessionId, usageState) setState("usage", sessionId, usageState)
} }
setState("sessions", sessionId, (session) => ({ setState("sessions", sessionId, (session) => ({
...session, ...session,
messageIds: incomingIds, messageIds: incomingIds,
updatedAt: Date.now(), updatedAt: Date.now(),
})) }))
bumpSessionRevision(sessionId) bumpSessionRevision(sessionId)
})
} }
function insertMessageIntoSession(sessionId: string, messageId: string) { function insertMessageIntoSession(sessionId: string, messageId: string) {

View File

@@ -121,10 +121,6 @@ function handleMessageUpdate(instanceId: string, event: MessageUpdateEvent | Mes
applyPartUpdateV2(instanceId, part) applyPartUpdateV2(instanceId, part)
withSession(instanceId, sessionId, () => {
/* trigger reactivity for legacy consumers */
})
updateSessionInfo(instanceId, sessionId) updateSessionInfo(instanceId, sessionId)
refreshPermissionsForSession(instanceId, sessionId) refreshPermissionsForSession(instanceId, sessionId)
} else if (event.type === "message.updated") { } else if (event.type === "message.updated") {
@@ -165,10 +161,6 @@ function handleMessageUpdate(instanceId: string, event: MessageUpdateEvent | Mes
upsertMessageInfoV2(instanceId, info, { status: "complete", bumpRevision: true }) upsertMessageInfoV2(instanceId, info, { status: "complete", bumpRevision: true })
withSession(instanceId, sessionId, () => {
/* ensure reactivity for legacy session observers */
})
updateSessionInfo(instanceId, sessionId) updateSessionInfo(instanceId, sessionId)
refreshPermissionsForSession(instanceId, sessionId) refreshPermissionsForSession(instanceId, sessionId)
} }