-
Notifications
You must be signed in to change notification settings - Fork 19
Switch to graphemer to split strings #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This switches to lodash-es to properly use a tree-shakable version of lodash. It also makes sure that we're including the lodash methods we use in the bundle instead of having it as a library dependency.
Deploying with
|
| Latest commit: |
d7afdea
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://67502f1d.compound-web.pages.dev |
| Branch Preview URL: | https://quenting-lodash-es.compound-web.pages.dev |
src/utils/string.ts
Outdated
| */ | ||
|
|
||
| import { split } from "lodash"; | ||
| import { split } from "lodash-es"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also worth pointing out EW hit bugs in Lodash's split grapheme splitting, we had to switch to graphemer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beaugunderson/emoji-aware#25 & lodash/lodash#5652 being related issues about this bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have opened element-hq/compound#196 to track this
|
Not that much, because this tree-shakes correctly, so only the methods we use (in this case, Library size with lodash-es not marked as external: and with it marked as external: So there is a 1.5kB difference gzipped |
Otherwise known as 36%... |
|
Alright fair, switching to |
t3chguy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bonus points for the flag test

I had a problem with consuming the ESM module in vitest.
The resulting bundle had a
import { split } from "lodash", which does not work because lodash is not an ESM module.There is an alternative
lodash-eswhich is an ESM module, but then using that would break some CJS environments.lodash's split function notably doesn't handle well some emoji graphemes, so instead this switches tographemerfixes element-hq/compound#196