Skip to content

Conversation

VipinDevelops
Copy link
Member

@VipinDevelops VipinDevelops commented Jul 7, 2025

Description

Fixes the issue of Emojis on the published page are significantly enlarged

Type of Change

  • Fix the image fall back from emojis
  • remove unsupported emojis from suggestions

Screenshots and Media (if applicable)

Test Scenarios

References

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive emoji support in the editor, including emoji insertion, rendering, and autocomplete suggestions.
    • Enabled conversion of typed or pasted emoji shortcodes (e.g., 😄) and Unicode emojis into emoji nodes.
    • Added emoji support to the read-only editor view.
  • Improvements

    • Enhanced emoji suggestion filtering to exclude unsupported emojis or those requiring fallback images, ensuring more relevant autocomplete results.

Copy link
Contributor

coderabbitai bot commented Jul 7, 2025

Walkthrough

A custom local Emoji extension for the TipTap editor was introduced, handling emoji insertion, rendering, and suggestions. The extension replaces the previous external emoji integration, updates suggestion filtering, and incorporates emoji support into the read-only editor configuration. Serialization logic was adjusted for consistency, with no changes to public APIs.

Changes

File(s) Change Summary
packages/editor/src/core/extensions/emoji/emoji.ts Added a new local Emoji extension implementing emoji node, insertion, rendering, suggestion, and Unicode-to-node replacement.
packages/editor/src/core/extensions/emoji/extension.ts Switched to using the local Emoji extension; updated imports and serialization formatting.
packages/editor/src/core/extensions/emoji/suggestion.ts Refined emoji suggestion filtering to exclude emojis requiring fallback images.
packages/editor/src/core/extensions/read-only-extensions.ts Integrated the new Emoji extension into the core read-only editor extensions array.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Editor
    participant EmojiExtension
    participant SuggestionPlugin

    User->>Editor: Types ":" + shortcode
    Editor->>EmojiExtension: Detects input rule
    EmojiExtension->>Editor: Inserts emoji node

    User->>Editor: Types or pastes Unicode emoji
    Editor->>EmojiExtension: Detects Unicode emoji in text
    EmojiExtension->>Editor: Replaces with emoji node

    User->>Editor: Types ":"
    Editor->>SuggestionPlugin: Triggers emoji suggestion
    SuggestionPlugin->>EmojiExtension: Fetches filtered emoji list
    User->>SuggestionPlugin: Selects emoji
    SuggestionPlugin->>Editor: Inserts emoji node and space
Loading

Possibly related PRs

Suggested labels

🐛bug, ✍️editor, 🌐frontend, ready to merge

Suggested reviewers

  • aaryan610
  • Palanikannan1437

Poem

In the meadow of code where emojis bloom,
A rabbit hops, dispelling old gloom.
With shortcodes and smiles,
Suggestions compile,
Now TipTap’s fields are in full emoji style!
🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3ce69b and 6ba30a9.

📒 Files selected for processing (1)
  • packages/editor/src/core/extensions/emoji/suggestion.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/editor/src/core/extensions/emoji/suggestion.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@VipinDevelops VipinDevelops changed the title fix: emoji fall back image [WIKI-524] fix: emoji fall back image Jul 7, 2025
Copy link

makeplane bot commented Jul 7, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2a62e2 and cba6dd7.

📒 Files selected for processing (4)
  • packages/editor/src/core/extensions/emoji/emoji.ts (1 hunks)
  • packages/editor/src/core/extensions/emoji/extension.ts (2 hunks)
  • packages/editor/src/core/extensions/emoji/suggestion.ts (1 hunks)
  • packages/editor/src/core/extensions/read-only-extensions.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/editor/src/core/extensions/read-only-extensions.ts (1)
packages/editor/src/core/extensions/emoji/extension.ts (1)
  • EmojiExtension (8-30)
🪛 Biome (1.9.4)
packages/editor/src/core/extensions/emoji/emoji.ts

[error] 155-155: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
packages/editor/src/core/extensions/read-only-extensions.ts (1)

36-36: LGTM!

The integration of the local EmojiExtension into the read-only editor extensions is properly implemented.

Also applies to: 77-77

packages/editor/src/core/extensions/emoji/extension.ts (1)

1-31: LGTM!

The migration to the local Emoji implementation is well-executed, maintaining the existing serialization logic while improving code consistency.

Comment on lines +149 to +158
const supportMap: Record<number, boolean> = removeDuplicates(emojis.map((item) => item.version))
.filter((version) => typeof version === "number")
.reduce((versions, version) => {
const emoji = emojis.find((item) => item.version === version && item.emoji);

return {
...versions,
[version as number]: emoji ? isEmojiSupported(emoji.emoji as string) : false,
};
}, {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Optimize the performance of emoji version support mapping

The spread syntax in the reducer causes O(n²) time complexity. Use a more efficient approach.

Apply this optimization:

 const supportMap: Record<number, boolean> = removeDuplicates(emojis.map((item) => item.version))
   .filter((version) => typeof version === "number")
-  .reduce((versions, version) => {
+  .reduce((versions, version) => {
     const emoji = emojis.find((item) => item.version === version && item.emoji);
-
-    return {
-      ...versions,
-      [version as number]: emoji ? isEmojiSupported(emoji.emoji as string) : false,
-    };
+    versions[version as number] = emoji ? isEmojiSupported(emoji.emoji as string) : false;
+    return versions;
   }, {});
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const supportMap: Record<number, boolean> = removeDuplicates(emojis.map((item) => item.version))
.filter((version) => typeof version === "number")
.reduce((versions, version) => {
const emoji = emojis.find((item) => item.version === version && item.emoji);
return {
...versions,
[version as number]: emoji ? isEmojiSupported(emoji.emoji as string) : false,
};
}, {});
const supportMap: Record<number, boolean> = removeDuplicates(
emojis.map((item) => item.version)
)
.filter((version) => typeof version === "number")
.reduce((versions, version) => {
const emoji = emojis.find(
(item) => item.version === version && item.emoji
);
versions[version as number] = emoji
? isEmojiSupported(emoji.emoji as string)
: false;
return versions;
}, {});
🧰 Tools
🪛 Biome (1.9.4)

[error] 155-155: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

🤖 Prompt for AI Agents
In packages/editor/src/core/extensions/emoji/emoji.ts around lines 149 to 158,
the reducer uses spread syntax inside the loop, causing O(n²) complexity. To fix
this, initialize the accumulator as an empty object and directly assign
properties to it within the reducer instead of spreading. This will improve
performance by avoiding repeated object copying.

Comment on lines 194 to 214
// const isSupported = this.storage.isSupported(emojiItem);
// const hasEmoji = !!emojiItem?.emoji;
// const hasFallbackImage = !!emojiItem?.fallbackImage;

const renderFallbackImage = false;

return [
"span",
attributes,
renderFallbackImage
? [
"img",
{
src: emojiItem.fallbackImage,
draggable: "false",
loading: "lazy",
align: "absmiddle",
},
]
: emojiItem.emoji || `:${emojiItem.shortcodes[0]}:`,
];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Enable fallback image rendering to align with PR objectives

The fallback image rendering is hardcoded to false, which defeats the purpose of this PR ("fix: emoji fall back image"). The commented code suggests the proper implementation was started but not completed.

Implement the fallback image logic:

-    // const isSupported = this.storage.isSupported(emojiItem);
-    // const hasEmoji = !!emojiItem?.emoji;
-    // const hasFallbackImage = !!emojiItem?.fallbackImage;
+    const isSupported = this.storage.isSupported(emojiItem);
+    const hasEmoji = !!emojiItem?.emoji;
+    const hasFallbackImage = !!emojiItem?.fallbackImage;

-    const renderFallbackImage = false;
+    const renderFallbackImage =
+      (this.options.forceFallbackImages && !hasEmoji) ||
+      (this.options.forceFallbackImages && hasFallbackImage) ||
+      (this.options.forceFallbackImages && !isSupported && hasFallbackImage) ||
+      ((!isSupported || !hasEmoji) && hasFallbackImage);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// const isSupported = this.storage.isSupported(emojiItem);
// const hasEmoji = !!emojiItem?.emoji;
// const hasFallbackImage = !!emojiItem?.fallbackImage;
const renderFallbackImage = false;
return [
"span",
attributes,
renderFallbackImage
? [
"img",
{
src: emojiItem.fallbackImage,
draggable: "false",
loading: "lazy",
align: "absmiddle",
},
]
: emojiItem.emoji || `:${emojiItem.shortcodes[0]}:`,
];
const isSupported = this.storage.isSupported(emojiItem);
const hasEmoji = !!emojiItem?.emoji;
const hasFallbackImage = !!emojiItem?.fallbackImage;
const renderFallbackImage =
(this.options.forceFallbackImages && !hasEmoji) ||
(this.options.forceFallbackImages && hasFallbackImage) ||
(this.options.forceFallbackImages && !isSupported && hasFallbackImage) ||
((!isSupported || !hasEmoji) && hasFallbackImage);
return [
"span",
attributes,
renderFallbackImage
? [
"img",
{
src: emojiItem.fallbackImage,
draggable: "false",
loading: "lazy",
align: "absmiddle",
},
]
: emojiItem.emoji || `:${emojiItem.shortcodes[0]}:`,
];
🤖 Prompt for AI Agents
In packages/editor/src/core/extensions/emoji/emoji.ts between lines 194 and 214,
the fallback image rendering is disabled by hardcoding renderFallbackImage to
false. To fix this, uncomment and use the existing logic to determine if the
fallback image should be rendered by checking if emojiItem has a fallbackImage
and if the storage supports it. Replace the hardcoded false with this condition
so the fallback image renders correctly when appropriate.

@VipinDevelops VipinDevelops requested a review from aaryan610 July 7, 2025 15:05
@pushya22 pushya22 merged commit ab79a5d into preview Jul 7, 2025
5 of 6 checks passed
@pushya22 pushya22 deleted the fix-emoji_fallback_image branch July 7, 2025 21:51
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.

3 participants