Skip to content

Commit b6f75d1

Browse files
committed
fix(messages): retain the cursor from a no-argument snapshot
The legacy Messages panel starts with list() and sends only the version on its next read. Remember the first snapshot for that peer so an ID removed and reused between reads appears in the delta.
1 parent 0b23ed4 commit b6f75d1

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

‎plugins/messages/src/node/rpc/functions/list.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export const messagesList = defineRpcFunction({
4242
? initial.instanceId
4343
: instanceId
4444
const result = host.listSince(since, knownInstance)
45-
// A legacy reader starts with null, or presents an unknown number
46-
// on a fresh connection. Keep its snapshot cursor for overlapping reads.
47-
if (peer && instanceId === undefined && since !== undefined && result.full && (!initial || initial.instanceId !== result.instanceId))
45+
// Keep the first snapshot cursor on this connection so overlapping
46+
// numeric reads can still see removals since that snapshot.
47+
if (peer && instanceId === undefined && result.full && (!initial || initial.instanceId !== result.instanceId))
4848
cursors.set(peer, { version: result.version, instanceId: result.instanceId })
4949
return result
5050
},

‎plugins/messages/test/dev-server.test.ts‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,24 @@ describe('messages dev-server (hub context)', () => {
7474
expect(delta.removedIds).toContain('from-server')
7575
})
7676

77-
it('returns full snapshots for foreign and unrecognized numeric cursors over RPC', async () => {
77+
it('returns a removal to a legacy panel after its no-argument snapshot', async () => {
7878
const rpc = connect(server)
79-
const full = await rpc.$call('devframes:plugin:messages:list') as DevframeMessagesListDelta
80-
for (const args of [
81-
[full.version],
82-
[full.version, 'previous-instance'],
83-
]) {
84-
const result = await rpc.$call('devframes:plugin:messages:list', ...args) as DevframeMessagesListDelta
85-
expect(result.full).toBe(true)
86-
expect(result.entries).toEqual(full.entries)
87-
expect(result.instanceId).toBe(full.instanceId)
88-
}
79+
const id = 'legacy-panel'
80+
await server.ctx.messages.info('original', { id })
81+
const snapshot = await rpc.$call('devframes:plugin:messages:list') as DevframeMessagesListDelta
82+
await server.ctx.messages.remove(id)
83+
await server.ctx.messages.info('replacement', { id })
84+
85+
const delta = await rpc.$call('devframes:plugin:messages:list', snapshot.version) as DevframeMessagesListDelta
86+
expect(delta.full).toBe(false)
87+
expect(delta.removedIds).toEqual([id])
88+
expect(delta.entries).toMatchObject([
89+
{ id, message: 'replacement' },
90+
])
91+
92+
const foreign = await rpc.$call('devframes:plugin:messages:list', snapshot.version, 'previous-instance') as DevframeMessagesListDelta
93+
expect(foreign.full).toBe(true)
94+
expect(foreign.instanceId).toBe(snapshot.instanceId)
8995
})
9096

9197
it('keeps the removal when a legacy reader sees an ID reused on its connection', async () => {

0 commit comments

Comments
 (0)