How to make postMessage type-safe in under 350 bytes
typed-channel wraps postMessage, BroadcastChannel, MessagePort and EventTarget behind one TypeScript-checked emit/on API, where message names and payloads are declared once in shared type maps and mirrored on each side. Transports are pluggable objects with just on and emit, so custom boundaries like Figma plugin sandboxes take about a dozen lines, and one channel can fan out over several transports. Version 0.11 adds createTypedRpcChannel with typed request/handle calls whose AbortSignal propagates to the remote handler, rejects on thrown errors, and cleans up pending requests on unlisten. The core is 271 bytes brotli-compressed (341 with the postMessage transport), while the RPC factory is a separate 1 kB import.
Related posts
- 500x faster postMessage(string)
Bun mediumAdept
Bun v1.2.21 makes postMessage(string) between workers nearly independent of string size, up to 500x faster with ~22x less peak memory on 3 MB strings (593 ns vs 326,290 ns in 1.2.20). JavaScriptCore strings are already immutable with atomic reference counts, so Bun skips Structured Clone serialization and shares the StringImpl pointer directly. Before sharing, it forces the lazy hash computation and marks the string never-atomicize. The fast path applies only to plain strings of at least 256 characters sent alone within the same process; atoms, symbols, substrings and ropes still get copied.
- Bun v0.7.0
Bun mediumAdept
Bun v0.7.0 focuses on Node.js compatibility: it can now run `vite dev` (experimentally, via `bun --bun` to override the node shebang), supports Web `Worker` threads with `postMessage` and `structuredClone()`, and implements `AsyncLocalStorage` from `node:async_hooks` as a step toward Next.js support. Other additions include a `--smol` flag that shrinks and slows growth of the JavaScriptCore heap for memory-constrained environments, `bun test --bail`, `Bun.readableStreamToFormData()`, `serialize`/`deserialize` in `bun:jsc`, WebSocket ping/pong with `nodebuffer` as the default binaryType, and many `node:tls` TLSSocket methods. Fixes include a Response memory leak that cut peak memory in a benchmark from 292 MB to 49 MB, base64url hash output matching Node.js, and module resolution ordering for dual CJS/ESM packages like graphql.
- Bun v0.7.2
Bun mediumAdept
Bun v0.7.2 adds node:worker_threads, node:diagnostics_channel and a global BroadcastChannel, lets structuredClone/postMessage clone Error objects, and adds `bun .` to run a project's main file. At runtime Bun stops honoring the "browser" and "module" package.json exports conditions, now resolving only bun, worker, node and default (plus import/require), which fixes breakage in Astro, axios and tslib-dependent packages. Two memory leaks are fixed: a ~16-byte leak in native strong references affecting fetch, Bun.spawn, napi and streams, and a double header clone in response.clone(). Large TypedArray creation gets up to 40x faster, and moving builtins from ESM to CommonJS cuts "crypto" import start time by about 30%.
- September in Servo: <progress>, rounded rectangles, and more!
Servo easyNovice
Servo 0.7.0 bundles 527 commits from September, adding web platform features such as the <progress> element, :checked, user-select, CSS typed arithmetic, alpha(), font-width, Canvas roundRect() and an MLKEM768-X25519 WebCrypto algorithm, plus many new DOM APIs. Embedding API changes include automatic throttling of hidden WebViews (set_throttled removed), embedder-driven focus via WebView::set_focused, WebGL in default features, an opt-out multiprocess Cargo feature (~2MB savings), and new SpiderMonkey GC threshold preferences for memory-constrained devices. Performance and memory work removed allocations, avoided IPC in single-process mode, reduced GC interactions and compacted data structures, alongside progress on accessibility, WebGL2, contenteditable editors, text tracks and IndexedDB.
- What's coming to JavaScript
Deno mediumAdeptTC39's 108th meeting advanced nine JavaScript proposals. Explicit Resource Management (`using`/`await using` with `Symbol.dispose`), `Array.fromAsync` and `Error.isError` reached stage 4, and Immutable `ArrayBuffer` (`transferToImmutable`, `sliceToImmutable`) reached stage 3. Earlier-stage proposals include seeded PRNGs, `Number.prototype.clamp`, `Intl.NumberFormat` trailing-zero control, a standard value-inspection format for diffs, and a `Random` namespace for sampling and shuffling. Each proposal comes with code examples and runtime support status, and Deno plans to use immutable buffers to avoid copies and disposable `AsyncContext.Variable` to simplify tracing spans.