Skip to content

Conversation

@Palanikannan1437
Copy link
Member

@Palanikannan1437 Palanikannan1437 commented Feb 11, 2025

Description

Bubble menu's weird flickering bug is now solved.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring

Test Scenarios

  • Rich Text editor and pages bubble functionalities needs to be tested.

Summary by CodeRabbit

  • Refactor

    • Streamlined text alignment and color selection components by switching to direct editor state evaluation.
    • Enhanced the overall bubble menu state management for clearer and more consistent formatting behavior.
  • Chores

    • Standardized naming by replacing "strikethrough" with "strike" across menu items and toolbar constants for consistency.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 11, 2025

Walkthrough

The changes update multiple editor components to simplify state management. The onClose prop is removed and replaced by an editorState prop in components like the TextAlignmentSelector and BubbleMenuColorSelector. The EditorBubbleMenu now uses a dedicated state hook and a new EditorStateType interface to consolidate formatting logic. Additionally, the strikethrough command is uniformly renamed to "strike" across menu items, constants, and type definitions.

Changes

File(s) Change Summary
packages/editor/.../bubble-menu/alignment-selector.tsx
packages/editor/.../bubble-menu/color-selector.tsx
packages/editor/.../bubble-menu/root.tsx
Replaced onClose with an editorState prop; updated internal logic to use editorState for checking active text alignment and color options; introduced a new state hook and EditorStateType interface to consolidate formatting states.
packages/editor/.../menu-items.ts
packages/editor/.../constants/common.ts
packages/editor/.../types/editor.ts
web/core/.../editor.ts
Renamed command and key from "strikethrough" to "strike" within menu items, constants, and type definitions to align terminology across the codebase.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Editor
    participant BubbleMenu as EditorBubbleMenu
    participant Align as TextAlignmentSelector
    participant Color as BubbleMenuColorSelector

    User->>Editor: Interact / Type text
    Editor->>BubbleMenu: Update state via useEditorState
    BubbleMenu->>Align: Pass updated editorState
    BubbleMenu->>Color: Pass updated editorState
    Align->>Editor: Check alignment state
    Color->>Editor: Check color state
Loading

Possibly related PRs

  • [PE-208] fix: floating toolbar content #6368: The changes in the main PR, specifically the updates to the TextAlignmentSelector component and its interaction with editorState, are related to the modifications in the EditorBubbleMenu component in the retrieved PR, as both involve the TextAlignmentSelector and its rendering logic.
  • [PE-67] fix: color extension not working on issue description and published page #5852: The changes in the main PR regarding the editorState prop in the TextAlignmentSelector component are related to the modifications in the BubbleMenuColorSelector component in the retrieved PR, as both involve updating the Props type to include editorState and altering internal logic to utilize this state.
  • [PULSE-42] feat: text alignment for all editors #5847: The changes in the main PR are related to the modifications in the TextAlignmentSelector component, which directly involves the handling of text alignment, while the retrieved PR introduces a new text alignment feature and integrates the TextAlignmentSelector into the editor's functionality.

Suggested labels

🐛bug, 🌐frontend, ✍️editor

Suggested reviewers

  • aaryan610
  • SatishGandham
  • sriramveeraghanta

Poem

I'm a coding bunny, hopping fast and free,
Tweaking states and props with simplicity.
Editor state flows like a gentle stream,
Alignments and colors now gleam in the dream.
With a hop and a skip, our code's a delight!
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@Palanikannan1437 Palanikannan1437 changed the title fix: bubble menu weird flickering fixed fix: bubble menu weird flickering Feb 11, 2025
@Palanikannan1437 Palanikannan1437 self-assigned this Feb 11, 2025
@Palanikannan1437 Palanikannan1437 marked this pull request as ready for review February 11, 2025 15:07
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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
web/core/constants/editor.ts (1)

96-129: ⚠️ Potential issue

Fix type signature inconsistency.

The type signature still uses "strikethrough" while the itemKey has been updated to "strike". This inconsistency should be fixed.

Apply this diff to update the type signature:

-const BASIC_MARK_ITEMS: ToolbarMenuItem<"bold" | "italic" | "underline" | "strikethrough">[] = [
+const BASIC_MARK_ITEMS: ToolbarMenuItem<"bold" | "italic" | "underline" | "strike">[] = [
🧹 Nitpick comments (4)
packages/editor/src/core/components/menus/bubble-menu/root.tsx (3)

7-7: Consider grouping imports for clarity.
Since you're already importing multiple menu items, consider grouping menu item imports together for improved readability.


19-20: Extending or clarifying constants.
COLORS_LIST is a convenient approach for color references. Consider adding a short comment describing its structure to aid maintainability.


104-104: Transition duration clarity.
Defining [300, 0] for the show/hide duration is fine, but consider documenting the intention or referencing design guidelines to avoid “magic numbers.”

packages/editor/src/core/components/menus/menu-items.ts (1)

145-151: Consider renaming the function for consistency.

While the type parameter and key have been updated to use "strike", the function name StrikeThroughItem still uses the old terminology. Consider renaming it to StrikeItem for consistency.

Apply this diff to rename the function:

-export const StrikeThroughItem = (editor: Editor): EditorMenuItem<"strike"> => ({
+export const StrikeItem = (editor: Editor): EditorMenuItem<"strike"> => ({

Don't forget to update all references to this function in other files.

🛑 Comments failed to post (1)
packages/editor/src/core/types/editor.ts (1)

34-34: 💡 Verification agent

🧩 Analysis chain

Verify the impact of renaming the strikethrough command.

The change from "strikethrough" to "strike" in TEditorCommands is a breaking change that could affect dependent code.

Run the following script to verify all usages of the strikethrough command:


🏁 Script executed:

#!/bin/bash
# Description: Search for any remaining references to "strikethrough" in the codebase.

# Search for "strikethrough" in TypeScript/JavaScript files
rg -t ts -t js -i 'strikethrough' --glob '!{*.test.*,*.spec.*}'

Length of output: 1345


Impact: Inconsistent Command Identifiers Detected

The change in TEditorCommands replacing "strikethrough" with "strike" is a breaking change. Our search shows that several parts of the code—such as in web/core/constants/editor.ts, packages/editor/src/core/constants/common.ts, and some UI components—still reference "strikethrough". These references will need to be updated to "strike" (or properly aliased) to ensure consistency and avoid type or runtime issues.

  • Action Required: Update dependent code (constants, menu items, etc.) to use "strike" in lieu of "strikethrough" to align with the updated public type.

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: 0

🧹 Nitpick comments (2)
packages/editor/src/core/components/menus/bubble-menu/root.tsx (2)

104-104: Consider adjusting tippy animation duration.

The current duration setting [300, 0] might cause the flickering issue. A shorter show duration could help.

-      duration: [300, 0],
+      duration: [150, 0],

144-147: Consider extracting className to a constant.

The className string is quite long and could be reused. Consider extracting it to a constant or utility function.

+const BUBBLE_MENU_CLASS = "flex py-2 divide-x divide-custom-border-200 rounded-lg border border-custom-border-200 bg-custom-background-100 shadow-custom-shadow-rg";

 <div
   ref={menuRef}
-  className="flex py-2 divide-x divide-custom-border-200 rounded-lg border border-custom-border-200 bg-custom-background-100 shadow-custom-shadow-rg"
+  className={BUBBLE_MENU_CLASS}
 >
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dad85d8 and d55c79d.

📒 Files selected for processing (7)
  • packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx (4 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx (1 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/root.tsx (6 hunks)
  • packages/editor/src/core/components/menus/menu-items.ts (1 hunks)
  • packages/editor/src/core/constants/common.ts (2 hunks)
  • packages/editor/src/core/types/editor.ts (1 hunks)
  • web/core/constants/editor.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/editor/src/core/types/editor.ts
  • web/core/constants/editor.ts
  • packages/editor/src/core/components/menus/menu-items.ts
  • packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx
  • packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx
  • packages/editor/src/core/constants/common.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (4)
packages/editor/src/core/components/menus/bubble-menu/root.tsx (4)

1-2: LGTM! Well-structured state management.

The new EditorStateType interface provides a comprehensive and type-safe way to manage editor state, and the imports are properly organized.

Also applies to: 28-46


48-78: LGTM! Improved state management with useEditorState hook.

The refactoring to use useEditorState hook and consolidating formatting items into an object improves code organization and maintainability.


113-139: LGTM! Improved event handling.

The addition of the menu reference check in handleMouseDown and proper event cleanup in the useEffect hook improves the robustness of the menu behavior.


159-185: LGTM! Clean conditional rendering.

The conditional rendering based on editorState.code and proper prop passing to child components is well implemented.

@sriramveeraghanta sriramveeraghanta merged commit 126575d into preview Feb 18, 2025
10 of 14 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix/bubble-menu branch February 18, 2025 20:39
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.

4 participants