Skip to content

MessagePort Transport

This package uses an internal MessagePort protocol between its client links and server handlers. The message shape is private implementation detail, not a public API. Use portLink(), mainPortLink(), createPortHandler(), or createWindowMessagePortHandler() instead of posting protocol messages manually.

Request inputs, response data, and error shapes are sent through MessagePort.postMessage().

When a tRPC data transformer is configured, values are transformed before they are posted to the port and transformed back after they are received:

  • client input: transformer.input.serialize()
  • server input: transformer.input.deserialize()
  • server result and error shapes: transformer.output.serialize()
  • client result and error shapes: transformer.output.deserialize()

This mirrors the data-transformer behavior users expect from tRPC links, while still using MessagePort as the underlying transport.

After any configured transformer runs, the value must still be accepted by the platform Structured Clone implementation used by Electron MessagePort.

Values such as JavaScript Proxy objects cannot be posted directly. Configure a tRPC transformer when you need those values converted into clone-safe data before transport.

Uint8Array and ArrayBuffer are supported by the MessagePort transport.

Blob is not currently supported as a MessagePort payload in this package. Electron renderer-to-main MessagePort transfer can deliver Blob-containing messages as null without throwing from postMessage(). Use ArrayBuffer or Uint8Array for binary payloads.

This page describes transport behavior, not the official tRPC JSON-RPC wire format. The internal MessagePort message shape may change between releases.