summaryrefslogtreecommitdiffhomepage
path: root/src/app/surface-protocol.svelte.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-10-21 14:26:35 +0900
committerAdam Malczewski <[email protected]>2026-10-21 14:26:35 +0900
commit8eefbc5287f73414df7feba6c78dc8ca73783b1d (patch)
treeecb0b0286f22eb082c8c4cce6adf1d535b0b7fed /src/app/surface-protocol.svelte.ts
parenta7b041f0f8989373404c35d3fe4b20b1e89d2440 (diff)
downloaddispatch-web-8eefbc5287f73414df7feba6c78dc8ca73783b1d.tar.gz
dispatch-web-8eefbc5287f73414df7feba6c78dc8ca73783b1d.zip
fix(review-followup-fea): clarify Stop with queued input
Diffstat (limited to 'src/app/surface-protocol.svelte.ts')
-rw-r--r--src/app/surface-protocol.svelte.ts20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/app/surface-protocol.svelte.ts b/src/app/surface-protocol.svelte.ts
index 4ba684d..400f612 100644
--- a/src/app/surface-protocol.svelte.ts
+++ b/src/app/surface-protocol.svelte.ts
@@ -16,8 +16,18 @@ export function createSurfaceProtocol(deps: {
send: SurfaceSocketHandle["send"];
}) {
let protocol = $state<ProtocolState>(protocolInitialState());
+ // Rendering may retain the prior spec during re-scope. Consumers making
+ // conversation-specific decisions can opt into a snapshot with a known scope.
+ let receivedScopes = $state<ReadonlyMap<string, string | undefined>>(new Map());
function handleServerMessage(msg: SurfaceServerMessage): void {
- protocol = applyServerMessage(protocol, msg);
+ const next = applyServerMessage(protocol, msg);
+ if (next !== protocol && (msg.type === "surface" || msg.type === "update")) {
+ const snapshot = msg.type === "surface" ? msg : msg.update;
+ const scopes = new Map(receivedScopes);
+ scopes.set(snapshot.spec.id, snapshot.conversationId);
+ receivedScopes = scopes;
+ }
+ protocol = next;
// Surfaces are auto-expanded: whenever the catalog changes, subscribe to
// every entry (and drop subscriptions for entries that vanished).
if (msg.type === "catalog") {
@@ -55,6 +65,7 @@ export function createSurfaceProtocol(deps: {
}
}
}
+ receivedScopes = new Map([...receivedScopes].filter(([id]) => protocol.subscriptions.has(id)));
}
/**
@@ -99,12 +110,17 @@ export function createSurfaceProtocol(deps: {
void conversationId;
const result = protocolUnsubscribe(protocol, surfaceId);
protocol = result.state;
+ const scopes = new Map(receivedScopes);
+ scopes.delete(surfaceId);
+ receivedScopes = scopes;
for (const msg of result.outgoing) {
deps.send(msg);
}
}
- function surfaceSpecOp(surfaceId: string): SurfaceSpec | null {
+ function surfaceSpecOp(surfaceId: string, conversationId?: string): SurfaceSpec | null {
+ if (conversationId !== undefined && receivedScopes.get(surfaceId) !== conversationId)
+ return null;
return getSurfaceSpec(protocol, surfaceId);
}