quick-review - Fix missing emoji in toast notification#9158
Conversation
|
Here is a sane explanation: The Problem: UTF-16 Surrogate PairsJavaScript strings are encoded in UTF-16, not Unicode code points. Most emojis require two UTF-16 code units (a surrogate pair) to represent a single character. The spread operator Why the count is 17 instead of 14The 3 extra elements come from multi-codepoint emojis — specifically emojis built from sequences joined by a Zero Width Joiner (ZWJ, U+200D) or variation selectors / modifier sequences. For example:
Quick illustrationconst flag = "🏳️🌈";
console.log(flag.length); // 6 (UTF-16 code units)
console.log([...flag].length); // 4 (code points: 🏳 + ️ + ZWJ + 🌈)
// spread still splits the ZWJ sequence into 4 separate elementsThe fix:
|
| Method | Splits on | Handles surrogate pairs | Handles ZWJ sequences |
|---|---|---|---|
str[i] / .length |
UTF-16 code units | ✗ | ✗ |
[...str] |
Unicode code points | ✓ | ✗ |
Intl.Segmenter |
Grapheme clusters | ✓ | ✓ |
|
That still doesn't explain it 😅 The explanation is that those extra characters are asking the renderer to render an emoji instead of the non-colored glyph |
Fixes #9156
Test URLs
Screenshot