Skip to content

[WIKI-710] [WIKI-717] fix: slash commands and mentions in comments#7919

Merged
pushya22 merged 2 commits intopreviewfrom
fix/mentions-floating-ui
Oct 7, 2025
Merged

[WIKI-710] [WIKI-717] fix: slash commands and mentions in comments#7919
pushya22 merged 2 commits intopreviewfrom
fix/mentions-floating-ui

Conversation

@Palanikannan1437
Copy link
Member

@Palanikannan1437 Palanikannan1437 commented Oct 7, 2025

Description

Floating ui - slash commands and mentions in pi chat editor/comments fixed overflow

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Summary by CodeRabbit

  • New Features

    • None
  • Bug Fixes

    • Prevented dropdowns from rendering when the selection position is unavailable, improving stability.
    • Fixed floating element positioning by attaching them to the editor container, reducing z-index and scroll issues.
    • Avoided duplicate or orphaned dropdown elements during updates.
  • Refactor

    • Streamlined dropdown lifecycle and position updates; removed redundant per-update syncing and manual DOM insertion for better reliability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 7, 2025

Walkthrough

Reorders guards and tightens lifecycle checks for mentions and slash-commands suggestions, removes manual document.body appends, and ensures floating UI elements are mounted to the editor container before computing position. No public API signatures changed.

Changes

Cohort / File(s) Change summary
Mentions suggestion lifecycle
packages/editor/src/core/extensions/mentions/utils.ts
Move clientRect guard to after creating the ReactRenderer; remove manual document.body append; add guards in onUpdate for missing component/element; always call position update with component.element.
Slash-commands suggestion lifecycle
packages/editor/src/core/extensions/slash-commands/root.tsx
Validate clientRect before activating dropbar and instantiating renderer; remove DOM append of dropdown; drop per-update component.updateProps and skip processing when clientRect is absent.
Floating UI positioning helper
packages/editor/src/core/helpers/floating-ui.ts
Resolve float container from editor.options.element (Element

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Editor
  participant Suggestion as Suggestion (Mentions/Slash)
  participant Renderer as ReactRenderer
  participant Float as FloatingUI

  User->>Editor: Type to trigger suggestion
  Editor->>Suggestion: onStart(props)
  Note right of Suggestion: Slash: pre-check clientRect\nMentions: instantiate then check clientRect
  Suggestion->>Suggestion: Validate clientRect
  alt clientRect present
    Suggestion->>Renderer: Instantiate component
    Suggestion->>Float: Append element to editor container
    Float->>Float: computePosition(with component.element)
    Float-->>Suggestion: Apply styles/position
  else
    Suggestion-->>Editor: Abort / no render
  end

  User->>Editor: Continue typing
  Editor->>Suggestion: onUpdate(props)
  Suggestion->>Suggestion: Guard component, element, and clientRect
  alt valid state
    Suggestion->>Float: updateFloatingUIFloaterPosition(component.element)
  else
    Suggestion-->>Editor: No-op
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

🐛bug, 🌐frontend, ✍️editor

Suggested reviewers

  • aaryan610
  • sriramveeraghanta
  • pushya22

Poem

I hop, I check the tiny rect,
No body-jumps, no wild eject.
I nestle in the editor's frame,
Position set — no two the same.
A rabbit's nod: the dropdown came. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The description provides a brief overview of the floating UI overflow fix and correctly indicates that it is a bug fix, but it omits sections required by the repository template such as Test Scenarios and References, and lacks detail on how the change was validated. Without these sections, reviewers cannot assess the tests performed or link to related issues. As a result, the PR description is incomplete. Please fill out the Test Scenarios section to describe how you verified the fix and add any relevant References to related issues or documentation. If applicable, include Screenshots to illustrate the before-and-after behavior of the floating UI. Providing these details will help reviewers assess the change and ensure it is properly tested and documented.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title clearly states that this PR fixes slash commands and mentions in comments and includes relevant Jira IDs, signaling a bug fix. It uses concise, direct phrasing without unnecessary noise and accurately reflects a real part of the change. While it does not explicitly mention floating UI overflow adjustments or the pi chat editor context, it remains related to the key changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/mentions-floating-ui

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/editor/src/core/helpers/floating-ui.ts (1)

34-34: Typo in error log message

Fix “floter” → “floater”.

-    .catch((error) => console.error("An error occurred while updating floating UI floter position:", error));
+    .catch((error) => console.error("An error occurred while updating floating UI floater position:", error));
🧹 Nitpick comments (4)
packages/editor/src/core/helpers/floating-ui.ts (1)

7-15: Append only once and allow custom mount container (appendTo) to prevent DOM reordering/clipping

Repeated appendChild can reorder the node on each update and cause stacking/flicker. Add an append guard and support a caller-provided container.

 export const updateFloatingUIFloaterPosition = (
   editor: Editor,
   element: HTMLElement,
   options?: {
     elementStyle?: Partial<CSSStyleDeclaration>;
     middleware?: Middleware[];
     placement?: Placement;
     strategy?: Strategy;
+    appendTo?: Element | (() => Element);
   }
 ) => {
-  ((editor.options.element || document.body) as Element).appendChild(element);
+  const container = (
+    (typeof options?.appendTo === "function" ? options.appendTo() : options?.appendTo) ||
+    editor.options.element ||
+    document.body
+  ) as Element;
+  if (element.parentElement !== container) {
+    container.appendChild(element);
+  }
packages/editor/src/core/extensions/mentions/utils.ts (2)

20-35: Avoid creating the renderer when clientRect is missing; centralize z-index via helper

Create the ReactRenderer only after validating clientRect and pass zIndex through the helper to keep stacking consistent.

       onStart: (props) => {
         if (!searchCallback) return;
-        component = new ReactRenderer<CommandListInstance, MentionsListDropdownProps>(MentionsListDropdown, {
-          props: {
-            ...props,
-            searchCallback,
-          },
-          editor: props.editor,
-        });
-        if (!props.clientRect) return;
+        if (!props.clientRect) return;
+        component = new ReactRenderer<CommandListInstance, MentionsListDropdownProps>(MentionsListDropdown, {
+          props: {
+            ...props,
+            searchCallback,
+          },
+          editor: props.editor,
+        });
         props.editor.commands.addActiveDropbarExtension(CORE_EXTENSIONS.MENTION);
         const element = component.element as HTMLElement;
-        element.style.position = "absolute";
-        element.style.zIndex = "100";
-        updateFloatingUIFloaterPosition(props.editor, element);
+        updateFloatingUIFloaterPosition(props.editor, element, {
+          elementStyle: { zIndex: "100" },
+        });
       },

37-41: Ensure z-index on update as well

If onStart exited early, the dropdown can lack z-index. Set it via helper on every update.

-        updateFloatingUIFloaterPosition(props.editor, component.element);
+        updateFloatingUIFloaterPosition(props.editor, component.element as HTMLElement, {
+          elementStyle: { zIndex: "100" },
+        });
packages/editor/src/core/extensions/slash-commands/root.tsx (1)

55-75: Early-return before renderer creation; centralize z-index via helper for consistent stacking

Prevents unnecessary renderer instantiation and ensures z-index is applied even if the first valid rect appears on update.

             onStart: (props) => {
               // Track active dropdown
-              component = new ReactRenderer<CommandListInstance, SlashCommandsMenuProps>(SlashCommandsMenu, {
-                props,
-                editor: props.editor,
-              });
-              if (!props.clientRect) return;
+              if (!props.clientRect) return;
+              component = new ReactRenderer<CommandListInstance, SlashCommandsMenuProps>(SlashCommandsMenu, {
+                props,
+                editor: props.editor,
+              });
               props.editor.commands.addActiveDropbarExtension(CORE_EXTENSIONS.SLASH_COMMANDS);
               const element = component.element as HTMLElement;
-              element.style.position = "absolute";
-              element.style.zIndex = "100";
-              updateFloatingUIFloaterPosition(props.editor, element);
+              updateFloatingUIFloaterPosition(props.editor, element, {
+                elementStyle: { zIndex: "100" },
+              });
             },
 
             onUpdate: (props) => {
               if (!component || !component.element) return;
               component.updateProps(props);
               if (!props.clientRect) return;
               const element = component.element as HTMLElement;
-              updateFloatingUIFloaterPosition(props.editor, element);
+              updateFloatingUIFloaterPosition(props.editor, element, {
+                elementStyle: { zIndex: "100" },
+              });
             },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 07ff457 and 66d5b8e.

📒 Files selected for processing (3)
  • packages/editor/src/core/extensions/mentions/utils.ts (1 hunks)
  • packages/editor/src/core/extensions/slash-commands/root.tsx (1 hunks)
  • packages/editor/src/core/helpers/floating-ui.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/editor/src/core/extensions/slash-commands/root.tsx (1)
packages/editor/src/core/helpers/floating-ui.ts (1)
  • updateFloatingUIFloaterPosition (4-35)
packages/editor/src/core/extensions/mentions/utils.ts (1)
packages/editor/src/core/helpers/floating-ui.ts (1)
  • updateFloatingUIFloaterPosition (4-35)
⏰ 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). (2)
  • GitHub Check: Build and lint web apps
  • GitHub Check: Analyze (javascript)

@Palanikannan1437 Palanikannan1437 changed the title fix: slash commands and mentions in comments [WIKI-710] [WIKI-717] fix: slash commands and mentions in comments Oct 7, 2025
@makeplane
Copy link

makeplane bot commented Oct 7, 2025

@pushya22 pushya22 merged commit c3e8ce8 into preview Oct 7, 2025
6 of 7 checks passed
@pushya22 pushya22 deleted the fix/mentions-floating-ui branch October 7, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants