[WIKI-710] [WIKI-717] fix: slash commands and mentions in comments#7919
[WIKI-710] [WIKI-717] fix: slash commands and mentions in comments#7919
Conversation
WalkthroughReorders guards and tightens lifecycle checks for mentions and slash-commands suggestions, removes manual Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 messageFix “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/clippingRepeated 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 helperCreate 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 wellIf 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 stackingPrevents 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
📒 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)
|
Linked to Plane Work Item(s)
This comment was auto-generated by Plane |
Description
Floating ui - slash commands and mentions in pi chat editor/comments fixed overflow
Type of Change
Summary by CodeRabbit
New Features
Bug Fixes
Refactor