Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class IPC {
send<T>(channel: string, data: T, options: SendOptions<T>): void
send<T = never>(channel: string, data?: T, options?: SendOptions<T>): void {
const id = generateId()
this.#sentIds.add(id)
const serialized = options?.serializer && data !== undefined
? options.serializer.serialize(data)
: data
Expand Down
17 changes: 17 additions & 0 deletions test/ipc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,23 @@ describe('IPC', () => {
}
})

it('ignores self-sent send packet on loopback', () => {
const handler = vi.fn()
ipc.on('ping', handler)

ipc.send('ping', { msg: 'hello' })

const sentPayload = mockTransport.send.mock.calls[0][1]
const sentPacket = JSON.parse(sentPayload)

mockTransport.simulateReceive(
`${SYSTEM_DOMAINS.PREFIX}:${SYSTEM_DOMAINS.USER}:test:ping`,
JSON.stringify(sentPacket),
)

expect(handler).not.toHaveBeenCalled()
})

it('ignores self-sent invoke packet on loopback', async () => {
ipc.handle('echo', (data: string) => `echo:${data}`)

Expand Down
Loading