Encode a string as UTF-8 bytes without TextEncoder.
TextEncoder is present in Node 22 and in every browser, but not in every
embedder the viewer is dropped into, and a digest that silently changes when
a polyfill differs is worse than a loop. Lone surrogates encode as U+FFFD,
which is what TextEncoder does, so an id carrying broken UTF-16 still
digests identically on both sides.
Encode a string as UTF-8 bytes without
TextEncoder.TextEncoderis present in Node 22 and in every browser, but not in every embedder the viewer is dropped into, and a digest that silently changes when a polyfill differs is worse than a loop. Lone surrogates encode as U+FFFD, which is whatTextEncoderdoes, so an id carrying broken UTF-16 still digests identically on both sides.