microdotblog / microblog-react

MIT License
29 stars 3 forks source link

Fix improper truncation of emojis in short bio #79

Closed in-the-trees closed 1 month ago

in-the-trees commented 2 months ago

Because emojis are technically multiple characters, the previous split method had the potential to break the rendering of them. I noticed this issue when viewing this profile:

To fix this, I matched the emojis with regex using Unicode's "EBNF rules". I ultimately got the pattern from this StackOverflow answer.

This was a lot trickier to fix than I expected it to be — it seems JavaScript isn't well prepared to handle this edge case. There are a number of libraries that solve this, but I figured solving this without depending on a library would be best.

Here's what my fix looks like:

I went through a number of others' profiles to ensure that the truncation still behaves as expected. As far as I saw, it does.


Also, is Prettier used for this app? My editor was picking up on the .prettierrc.js file in this repo, but it seems the files aren't formatted using it.

vincentritter commented 1 month ago

This is fantastic, thank you. I'll be looking at this in the coming week and give it a test my end and will merge in.

manton commented 1 month ago

Excellent, thanks @in-the-trees!

vincentritter commented 1 month ago

Thanks again @in-the-trees, all merged in. I will look at the prettier file — we don't use it.

manton commented 1 month ago

This fix is in version 3.2.7 which I just submitted to Apple.