Skip to content

Commit

Permalink
fix: Cannot read properties of undefined (reading 'replace'), closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
tommoor committed Dec 27, 2024
1 parent ad237a6 commit f0fcb26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion shared/editor/lib/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const nameToEmoji: Record<string, string> = Object.values(
* @returns The emoji character
*/
export const getEmojiFromName = (name: string) =>
nameToEmoji[name.replace(/:/g, "")];
nameToEmoji[name.replace(/:/g, "")] ?? "?";

/**
* Get the emoji shortcode for a given emoji character.
Expand Down
26 changes: 11 additions & 15 deletions shared/editor/nodes/Emoji.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ export default class Emoji extends Extension {
get schema(): NodeSpec {
return {
attrs: {
style: {
default: "",
},
"data-name": {
default: undefined,
default: "grey_question",
validate: "string",
},
},
inline: true,
Expand All @@ -50,17 +48,15 @@ export default class Emoji extends Extension {
],
toDOM: (node) => {
const name = node.attrs["data-name"];
if (name && getEmojiFromName(name)) {
return [
"strong",
{
class: `emoji ${name}`,
"data-name": name,
},
getEmojiFromName(name),
];
}
return ["strong", { class: "emoji" }, `:${name}:`];

return [
"strong",
{
class: `emoji ${name}`,
"data-name": name,
},
getEmojiFromName(name),
];
},
toPlainText: (node) => getEmojiFromName(node.attrs["data-name"]),
};
Expand Down

0 comments on commit f0fcb26

Please sign in to comment.