Skip to content

Fix width of emoji ZWJ sequences with skin tone modifiers - #20108

Open
lazerg wants to merge 2 commits into
prettier:mainfrom
lazerg:fix/issue-20105-emoji-grapheme-width
Open

lazerg wants to merge 2 commits into
prettier:mainfrom
lazerg:fix/issue-20105-emoji-grapheme-width

Conversation

@lazerg

@lazerg lazerg commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Description

emoji-regex matches each part of a skin tone modified ZWJ sequence on its own, so 👨🏻‍👩🏻‍👧🏻‍👦🏻 was measured as four separate emojis and GFM tables ended up padded to eight columns instead of two. The same sequence without the skin tone modifiers matches as a whole and was already correct.

Joining the matches back over U+200D before measuring makes the whole sequence count as one double width emoji.

Fixes #20105

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.
  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

@pkg-pr-new

pkg-pr-new Bot commented Sep 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

yarn add https://pkg.pr.new/@prettier/plugin-hermes@20108.tgz
yarn add https://pkg.pr.new/@prettier/plugin-oxc@20108.tgz
yarn add https://pkg.pr.new/@prettier/plugin-yuku@20108.tgz
yarn add https://pkg.pr.new/prettier@20108.tgz

commit: 4c71ae2

@netlify

netlify Bot commented Sep 19, 2026

Copy link
Copy Markdown

Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 4c71ae2
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6aade93d1f0dd1000827823a
😎 Deploy Preview https://deploy-preview-20108--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@lazerg

lazerg commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

The Node.js 18 job fails the same way on other open PRs, for example #20107 and #20103, so it is not caused by this change.

@fisker

fisker commented Sep 19, 2026

Copy link
Copy Markdown
Member

Should it be fixed on emoji-regex side?

@lazerg

lazerg commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

No. emoji-regex follows the Unicode RGI set, and 👨🏻‍👩🏻‍👧🏻‍👦🏻 is not in it. V8 agrees — /\p{RGI_Emoji}/v splits that string into the same four matches:

"👨🏻‍👩🏻‍👧🏻‍👦🏻".match(/\p{RGI_Emoji}/gv)
// [ '👨🏻', '👩🏻', '👧🏻', '👦🏻' ]
"👨‍👩‍👧‍👦".match(/\p{RGI_Emoji}/gv)
// [ '👨‍👩‍👧‍👦' ]

Family sequences with skin tone modifiers were never added to RGI, unlike handshake or holding-hands. Asking emoji-regex to match them means matching non-RGI sequences, which drops the determinism the package promises.

The emojiRegex().test(...) check in the issue is misleading. test is true for any substring match, so it passes on the first part alone.

We need display width per grapheme cluster, not RGI membership. Intl.Segmenter reports one cluster here, so the join belongs on our side. The file already has a TODO to move to Intl.Segmenter — I can do that instead if you prefer.

@fisker

fisker commented Sep 19, 2026

Copy link
Copy Markdown
Member

I'll wait for mathiasbynens/emoji-regex#122

@fisker

fisker commented Sep 19, 2026

Copy link
Copy Markdown
Member

The file already has a TODO to move to Intl.Segmenter — I can do that instead if you prefer.

Can't do it since we support Node.js v14

@lazerg

lazerg commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

Right, Node 14 rules out Intl.Segmenter. I'll keep the regex workaround in get-string-width.js as is.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown: 👨🏻‍👩🏻‍👧🏻‍👦🏻 (family emoji with skin modifiers) in GFM table is not treated as double width emoji

2 participants