Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/lodash-es": "^4.17.8",
"@types/node": "^20.4.5",
"@types/react": "^18.2.18",
"@types/testing-library__jest-dom": "^5.14.9",
Expand Down Expand Up @@ -99,7 +98,7 @@
"dependencies": {
"@radix-ui/react-form": "^0.0.3",
"classnames": "^2.3.2",
"lodash": "^4.17.21"
"graphemer": "^1.4.0"
},
"peerDependencies": {
"@fontsource/inter": "^5",
Expand Down
9 changes: 9 additions & 0 deletions src/components/Avatar/Avatar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ describe("Avatar", () => {
expect(container).toHaveTextContent("🤓");
});

it("does not split the flag emoji as first letter", () => {
// This was a bug in the past, because we were relying on lodash's `split`,
// which handles some graphemes incorrectly.
const { container } = render(
<Avatar name="🏴󠁧󠁢󠁷󠁬󠁳󠁿 John" id="@john:example.org" />,
);
expect(container).toHaveTextContent("🏴󠁧󠁢󠁷󠁬󠁳󠁿");
});

it.each([
["@bob:example.org", "8"],
["@alice:example.org", "3"],
Expand Down
8 changes: 5 additions & 3 deletions src/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { split } from "lodash";
import GraphemeSplitter from "graphemer";

export const MX_USERNAME_PREFIX = "@";
export const MX_ROOM_PREFIX = "#";
Expand All @@ -36,6 +36,8 @@ export function getInitialLetter(name: string): string {
name = name.substring(1);
}

// rely on the grapheme cluster splitter in lodash so that we don't break apart compound emojis
return split(name, "", 1)[0];
// rely on a grapheme cluster splitter so that we don't break apart compound emojis
const splitter = new GraphemeSplitter();
const result = splitter.iterateGraphemes(name).next();
return result.done ? "" : result.value;
}
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default defineConfig({
"react-dom/server",
"react/jsx-runtime",
"react/jsx-dev-runtime",
"lodash",
"classnames",
"graphemer",
"@radix-ui/react-form",
],

Expand Down
9 changes: 1 addition & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3434,14 +3434,7 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.12.tgz#d70faba7039d5fca54c83c7dbab41051d2b6f6cb"
integrity sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==

"@types/lodash-es@^4.17.8":
version "4.17.8"
resolved "https://registry.yarnpkg.com/@types/lodash-es/-/lodash-es-4.17.8.tgz#cfffd0969507830c22da18dbb20d2ca126fdaa8b"
integrity sha512-euY3XQcZmIzSy7YH5+Unb3b2X12Wtk54YWINBvvGQ5SmMvwb11JQskGsfkH/5HXK77Kr8GF0wkVDIxzAisWtog==
dependencies:
"@types/lodash" "*"

"@types/lodash@*", "@types/lodash@^4.14.167":
"@types/lodash@^4.14.167":
version "4.14.196"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.196.tgz#a7c3d6fc52d8d71328b764e28e080b4169ec7a95"
integrity sha512-22y3o88f4a94mKljsZcanlNWPzO0uBsBdzLAngf2tp533LzZcQzb6+eZPJ+vCTt+bqF2XnvT9gejTLsAcJAJyQ==
Expand Down