My Favorite Bugs: Invalid Surrogate Pairs
Summary
Two emoji surrogate pairs triggered a rare bug in a CRDT-based editor, causing edits to disappear due to surrogate splits during string encoding. The article explains code units, code points, and grapheme clusters, how slice() can break characters, and describes the fixes (lib0 patch and making emoji an atomic node) and a modern grapheme-aware approach using Intl.Segmenter.