Skip to content

refactor: decouple autocomplete engine via EditableTextAdapter#40925

Draft
ricardogarim wants to merge 1 commit into
refactor/autocomplete-movefrom
refactor/composer-autocomplete-engine
Draft

refactor: decouple autocomplete engine via EditableTextAdapter#40925
ricardogarim wants to merge 1 commit into
refactor/autocomplete-movefrom
refactor/composer-autocomplete-engine

Conversation

@ricardogarim

@ricardogarim ricardogarim commented Jun 11, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

Makes the relocated engine reusable by any text input, not just the chat composer — no behavior change for the composer, original names kept:

  • inject text access through an EditableTextAdapter (the composer builds its adapter from chat.composer) instead of reaching into ChatContext/ChatAPI
  • lift slash-command preview knowledge into the config via enablePreviewQuery (engine no longer imports slashCommands)
  • extract the emoji : config into a shared EmojiAutocomplete module (logic preserved verbatim)
  • add engine + emoji unit tests

Issue(s)

PRES-30

Steps to test or reproduce

Composer autocomplete works unchanged. Unit tests: useComposerBoxPopup.spec.tsx, emojiPopupConfig.spec.tsx.

Further comments

Stacked on PR #41050. The input-side adapter (fromInputElement) ships with its first consumer, #40926.

@dionisio-bot

dionisio-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is targeting the wrong base branch. It should target 8.7.0, but it targets 8.6.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2bdb4bb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b790b4a2-aa68-4630-b4f9-44c2bd1b5ec2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Extracts ComposerPopupOption<T>, createMessageBoxPopupConfig, and EditableTextAdapter into shared AutocompletePopup modules. Refactors useComposerBoxPopup to accept an EditableTextAdapter instead of reading directly from the chat composer context. Moves emoji popup config and component from the composer directory into a new EmojiAutocomplete module with dedicated tests. Updates all consumers accordingly.

Changes

AutocompletePopup Refactor and Emoji Config Extraction

Layer / File(s) Summary
ComposerPopupOption type, factory, EditableTextAdapter, and barrel
apps/meteor/client/components/AutocompletePopup/ComposerPopupOption.ts, apps/meteor/client/components/AutocompletePopup/editableTextAdapter.ts, apps/meteor/client/components/AutocompletePopup/index.ts
Introduces ComposerPopupOption<T> with all trigger/data-source/preview/render fields; createMessageBoxPopupConfig with defaults for blur/escape/prefix/getValue; EditableTextAdapter with textBeforeCaret, caret, and replaceRange; barrel re-exports all.
useComposerBoxPopup refactor to EditableTextAdapter
apps/meteor/client/components/AutocompletePopup/hooks/useComposerBoxPopup.ts, apps/meteor/client/components/AutocompletePopup/hooks/useComposerBoxPopupQueries.ts, apps/meteor/client/components/AutocompletePopup/hooks/useEnablePopupPreview.ts
Hook signature updated to (options: ComposerPopupOption<T>[], editor: EditableTextAdapter | undefined); select and setOptionByInput use adapter methods; arrow-key navigation removes type casts. Queries hook drops slashCommands dependency and simplifies enableQuery to popup.enablePreviewQuery?.(filter).
useComposerBoxPopup tests
apps/meteor/client/components/AutocompletePopup/hooks/useComposerBoxPopup.spec.tsx
New test suite using mock EditableTextAdapter covering trigger detection, triggerLength gating, start-only trigger, text replacement ranges, arrow-key wraparound navigation, Enter selection, and Escape close.
ComposerBoxPopup component minor fixes
apps/meteor/client/components/AutocompletePopup/ComposerBoxPopup.tsx
Renames internal ref to popupRef, passes it to useContentBoxSize and Tile; adds explicit return undefined in getOptionTitle after the disabled branch.
Emoji popup config and tests
apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.tsx, apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.spec.tsx
Exports ComposerBoxPopupEmojiProps, ComposerBoxPopupEmoji (renders emoji handle + _id), and createEmojiPopupConfig (: trigger, length 2, tone/color rules, exact/prefix/recency sort, 10-item cap). Tests validate substring matching, ranking, recent-emoji boosting, skin-tone visibility, and suggestion limit.
Context, provider, and MessageBox consumer wiring
apps/meteor/client/views/room/contexts/ComposerPopupContext.ts, apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx, apps/meteor/client/views/room/composer/messageBox/MessageBox.tsx, apps/meteor/client/views/room/composer/ComposerBoxPopupPreview.tsx
ComposerPopupContext removes local type/factory, importing from shared module. Provider replaces inline emoji popup with createEmojiPopupConfig, updates emoji item shape to { _id }, and adds enablePreviewQuery to command popup. MessageBox builds EditableTextAdapter from chat.composer and passes it to the hook. ComposerBoxPopupPreview updates import path.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • ggazzo
  • KevLehman
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR: decoupling the autocomplete engine from chat-specific dependencies through the introduction of an EditableTextAdapter.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • PRES-30: Request failed with status code 401

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.

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.87395% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.17%. Comparing base (9159c5d) to head (2bdb4bb).

Additional details and impacted files

Impacted file tree graph

@@                      Coverage Diff                       @@
##           refactor/autocomplete-move   #40925      +/-   ##
==============================================================
+ Coverage                       70.16%   70.17%   +0.01%     
==============================================================
  Files                            3361     3368       +7     
  Lines                          129686   130267     +581     
  Branches                        22489    22564      +75     
==============================================================
+ Hits                            90996    91417     +421     
- Misses                          35378    35541     +163     
+ Partials                         3312     3309       -3     
Flag Coverage Δ
unit 70.08% <84.87%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ricardogarim

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot added the type: feature Pull requests that introduces new feature label Jun 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
packages/ui-client/src/components/AutocompletePopup/AutocompletePopup.tsx (1)

86-90: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Only set aria-labelledby when the title element exists.

When title is falsy, the header <Box id={id}> is not rendered but the popup still points aria-labelledby at that missing node. That leaves the no-title case with a broken accessible-name reference.

Suggested fix
-			<Tile ref={popupRef} padding={0} role='menu' mbe={8} overflow='hidden' aria-labelledby={id} name='AutocompletePopup'>
+			<Tile
+				ref={popupRef}
+				padding={0}
+				role='menu'
+				mbe={8}
+				overflow='hidden'
+				{...(title ? { 'aria-labelledby': id } : {})}
+				name='AutocompletePopup'
+			>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui-client/src/components/AutocompletePopup/AutocompletePopup.tsx`
around lines 86 - 90, The Tile currently always sets aria-labelledby={id} even
when title is falsy and the header Box (id) isn't rendered; update the
AutocompletePopup rendering so aria-labelledby is only set when title exists
(e.g., conditionally pass id or undefined/omit the attribute). Locate the Tile
element using identifiers Tile, popupRef, id and the title prop in
AutocompletePopup and change the prop to be conditional on title so the
accessible-name reference is not broken when no header is rendered.
🧹 Nitpick comments (1)
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx (1)

188-242: ⚡ Quick win

The +: emoji option is already drifting from the shared emoji config.

This block duplicates the emoji filtering/tone logic you just extracted into createEmojiPopupConfig, but with a different ranking implementation and no coverage from apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.spec.tsx. Please extract the common local search/sort helper so both : and +: stay behaviorally aligned.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx` around
lines 188 - 242, The local emoji filtering/sorting logic duplicated inside the
getItemsFromLocal of the createAutocompletePopupConfig (the '+:' config) should
be extracted into a shared helper used by both createEmojiPopupConfig and the
'+:' getItemsFromLocal; specifically factor out the regexes (exactFinalTone,
colorBlind, seeColor), the recents mapping and emojiSort comparator, and the
filter/sort/slice pipeline (currently using escapeRegExp, key, recents,
collection) into a function (e.g., createEmojiLocalSearch or
filterAndSortEmojis) and replace the inline implementation in getItemsFromLocal
and createEmojiPopupConfig to call it; also add/adjust tests in
emojiPopupConfig.spec.tsx to cover the shared helper behavior for both ':' and
'+:' cases so ranking stays aligned.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts`:
- Around line 7-19: The composer-level Escape is still handled before the popup
because useAutocompletePopup only consumes Escape on keyup; fix by intercepting
Escape on keydown inside useComposerBoxPopup so the popup gets first dibs: when
mounting, add a keydown listener that checks for key === 'Escape' and popup-open
state (from the popup hook—expose or derive an isOpen flag from
useAutocompletePopup's return value) and when open calls event.preventDefault()
and event.stopImmediatePropagation()/stopPropagation() so MessageBox's Escape
handler doesn't run; ensure you clean up the listener on unmount and keep the
existing return shape of useComposerBoxPopup so consumers (MessageBox) don't
need changes. Reference symbols: useComposerBoxPopup, useAutocompletePopup, and
the Escape handler in MessageBox (MessageBox.tsx).

---

Outside diff comments:
In `@packages/ui-client/src/components/AutocompletePopup/AutocompletePopup.tsx`:
- Around line 86-90: The Tile currently always sets aria-labelledby={id} even
when title is falsy and the header Box (id) isn't rendered; update the
AutocompletePopup rendering so aria-labelledby is only set when title exists
(e.g., conditionally pass id or undefined/omit the attribute). Locate the Tile
element using identifiers Tile, popupRef, id and the title prop in
AutocompletePopup and change the prop to be conditional on title so the
accessible-name reference is not broken when no header is rendered.

---

Nitpick comments:
In `@apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx`:
- Around line 188-242: The local emoji filtering/sorting logic duplicated inside
the getItemsFromLocal of the createAutocompletePopupConfig (the '+:' config)
should be extracted into a shared helper used by both createEmojiPopupConfig and
the '+:' getItemsFromLocal; specifically factor out the regexes (exactFinalTone,
colorBlind, seeColor), the recents mapping and emojiSort comparator, and the
filter/sort/slice pipeline (currently using escapeRegExp, key, recents,
collection) into a function (e.g., createEmojiLocalSearch or
filterAndSortEmojis) and replace the inline implementation in getItemsFromLocal
and createEmojiPopupConfig to call it; also add/adjust tests in
emojiPopupConfig.spec.tsx to cover the shared helper behavior for both ':' and
'+:' cases so ranking stays aligned.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6622c386-3f4e-4e4c-bda3-a06bb8ed5135

📥 Commits

Reviewing files that changed from the base of the PR and between a6bebd2 and f6ed427.

📒 Files selected for processing (17)
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.spec.tsx
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.tsx
  • apps/meteor/client/views/room/composer/ComposerBoxPopupEmoji.tsx
  • apps/meteor/client/views/room/composer/ComposerBoxPopupPreview.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.spec.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopupQueries.ts
  • apps/meteor/client/views/room/composer/hooks/useEnablePopupPreview.ts
  • apps/meteor/client/views/room/composer/messageBox/MessageBox.tsx
  • apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
  • apps/meteor/tests/e2e/page-objects/fragments/composer.ts
  • packages/ui-client/src/components/AutocompletePopup/AutocompletePopup.tsx
  • packages/ui-client/src/components/AutocompletePopup/index.ts
  • packages/ui-client/src/components/index.ts
  • packages/ui-client/src/hooks/index.ts
  • packages/ui-client/src/hooks/useAutocompletePopup.ts
💤 Files with no reviewable changes (3)
  • apps/meteor/client/views/room/composer/ComposerBoxPopupEmoji.tsx
  • apps/meteor/client/views/room/composer/hooks/useEnablePopupPreview.ts
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopupQueries.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/ui-client/src/hooks/index.ts
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.spec.tsx
  • apps/meteor/tests/e2e/page-objects/fragments/composer.ts
  • packages/ui-client/src/components/index.ts
  • apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
  • packages/ui-client/src/components/AutocompletePopup/index.ts
  • apps/meteor/client/views/room/composer/ComposerBoxPopupPreview.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.spec.tsx
  • packages/ui-client/src/components/AutocompletePopup/AutocompletePopup.tsx
  • apps/meteor/client/views/room/composer/messageBox/MessageBox.tsx
  • packages/ui-client/src/hooks/useAutocompletePopup.ts
  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
apps/meteor/tests/e2e/page-objects/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

Utilize existing page objects pattern from apps/meteor/tests/e2e/page-objects/

Files:

  • apps/meteor/tests/e2e/page-objects/fragments/composer.ts
apps/meteor/tests/e2e/**/*.{ts,spec.ts}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

apps/meteor/tests/e2e/**/*.{ts,spec.ts}: Store commonly used locators in variables/constants for reuse
Follow Page Object Model pattern consistently in Playwright tests

Files:

  • apps/meteor/tests/e2e/page-objects/fragments/composer.ts
🧠 Learnings (10)
📚 Learning: 2026-01-19T18:08:05.314Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38169
File: packages/ui-client/src/hooks/useGoToDirectMessage.ts:20-27
Timestamp: 2026-01-19T18:08:05.314Z
Learning: Rule of Hooks: In React, hooks (including custom hooks like useGoToDirectMessage and useUserSubscriptionByName) must be called unconditionally and in the same order on every render. Do not conditionally call hooks based on values; instead, derive safe inputs if a value may be undefined (e.g., pass an empty string or undefined) and handle variations in logic outside the hook invocation. This preserves hook order and avoids violations. Apply this guideline to all files under packages/ui-client/src/hooks where hooks are used.

Applied to files:

  • packages/ui-client/src/hooks/index.ts
  • packages/ui-client/src/hooks/useAutocompletePopup.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/ui-client/src/hooks/index.ts
  • apps/meteor/tests/e2e/page-objects/fragments/composer.ts
  • packages/ui-client/src/components/index.ts
  • apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
  • packages/ui-client/src/components/AutocompletePopup/index.ts
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
  • packages/ui-client/src/hooks/useAutocompletePopup.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/ui-client/src/hooks/index.ts
  • apps/meteor/tests/e2e/page-objects/fragments/composer.ts
  • packages/ui-client/src/components/index.ts
  • apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
  • packages/ui-client/src/components/AutocompletePopup/index.ts
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
  • packages/ui-client/src/hooks/useAutocompletePopup.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • packages/ui-client/src/hooks/index.ts
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.spec.tsx
  • apps/meteor/tests/e2e/page-objects/fragments/composer.ts
  • packages/ui-client/src/components/index.ts
  • apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
  • packages/ui-client/src/components/AutocompletePopup/index.ts
  • apps/meteor/client/views/room/composer/ComposerBoxPopupPreview.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.spec.tsx
  • packages/ui-client/src/components/AutocompletePopup/AutocompletePopup.tsx
  • apps/meteor/client/views/room/composer/messageBox/MessageBox.tsx
  • packages/ui-client/src/hooks/useAutocompletePopup.ts
  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2026-03-06T18:10:15.268Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:15.268Z
Learning: In tests (especially those using testing-library/dom/jsdom) for Rocket.Chat components, the HTML <code> element has an implicit ARIA role of 'code'. Therefore, screen.getByRole('code') or screen.findByRole('code') will locate <code> elements even without a role attribute. Do not flag findByRole('code') as invalid in reviews; prefer using the implicit role instead of adding role="code" unless necessary for accessibility.

Applied to files:

  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.spec.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.spec.tsx
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.spec.tsx
  • apps/meteor/client/views/room/composer/ComposerBoxPopupPreview.tsx
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.spec.tsx
  • packages/ui-client/src/components/AutocompletePopup/AutocompletePopup.tsx
  • apps/meteor/client/views/room/composer/messageBox/MessageBox.tsx
  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2025-12-16T17:29:40.430Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37834
File: apps/meteor/tests/e2e/page-objects/fragments/admin-flextab-emoji.ts:12-22
Timestamp: 2025-12-16T17:29:40.430Z
Learning: In all page-object files under apps/meteor/tests/e2e/page-objects/, import expect from ../../utils/test (Playwright's async expect) instead of from Jest. Jest's expect is synchronous and incompatible with web-first assertions like toBeVisible, which can cause TypeScript errors.

Applied to files:

  • apps/meteor/tests/e2e/page-objects/fragments/composer.ts
📚 Learning: 2026-02-24T19:39:42.247Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/page-objects/fragments/message.ts:7-7
Timestamp: 2026-02-24T19:39:42.247Z
Learning: In RocketChat e2e tests, avoid using data-qa attributes to locate elements. Prefer semantic locators such as getByRole, getByLabel, getByText, getByTitle and ARIA-based selectors. Apply this rule to all TypeScript files under apps/meteor/tests/e2e to improve test reliability, accessibility, and maintainability.

Applied to files:

  • apps/meteor/tests/e2e/page-objects/fragments/composer.ts
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.

Applied to files:

  • apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
🪛 ast-grep (0.43.0)
packages/ui-client/src/hooks/useAutocompletePopup.ts

[warning] 210-210: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^| |\n)(${option.trigger})([^\\s]*$))
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 210-210: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^)(${option.trigger})([^\\s]*$))
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 238-238: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^| |\n)(${trigger})[^\\s]*$)
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 238-238: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^)(${trigger})[^\\s]*$)
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 256-256: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^| |\n)(${option.trigger})([^\\s]*$))
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 256-256: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^)(${option.trigger})([^\\s]*$))
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)

🔇 Additional comments (2)
packages/ui-client/src/hooks/useAutocompletePopup.ts (1)

210-211: Escape trigger before interpolating it into selector RegExps (3 call sites).

useAutocompletePopup builds regexes via new RegExp(\...(${option.trigger})...`)/new RegExp(`...(${trigger})...`)at lines 210-211, 238-239, and 256-257, without escaping metacharacters. The repo currently supplies the composer “plus” trigger astrigger: '\+:'(i.e.,+:), but other consumers/configs could pass unescaped triggers like +:/?/(, which would produce an invalid/incorrect selector and break matching (and may throw). Add an internal escapeRegExp(or equivalent) and apply it totrigger` at all three construction sites.

apps/meteor/tests/e2e/page-objects/fragments/composer.ts (1)

111-111: LGTM!

Comment thread apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts Outdated
@ricardogarim ricardogarim marked this pull request as ready for review June 12, 2026 13:07
@ricardogarim ricardogarim requested a review from a team as a code owner June 12, 2026 13:07

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 issues found across 17 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/ui-client/src/hooks/useAutocompletePopup.ts Outdated
@ricardogarim ricardogarim added this to the 8.6.0 milestone Jun 12, 2026
@ricardogarim ricardogarim force-pushed the refactor/composer-autocomplete-engine branch from f6ed427 to 862f80f Compare June 18, 2026 19:42
@ricardogarim ricardogarim marked this pull request as draft June 18, 2026 19:42

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts`:
- Around line 158-173: The `handleKeyUp` callback uses a stale `option` variable
after calling `setOptionByInput()` because React state updates are asynchronous,
causing the `closeOnEsc` configuration check to reference the pre-update option
value. Capture the return value from the `setOptionByInput()` call and use that
returned option instead of the stale `option` variable for the subsequent null
check and the `closeOnEsc` condition check on line 167.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 70d7b697-55d2-4b98-a68d-f81ee9193d97

📥 Commits

Reviewing files that changed from the base of the PR and between f6ed427 and 862f80f.

📒 Files selected for processing (17)
  • apps/meteor/client/components/AutocompletePopup/AutocompletePopupOption.ts
  • apps/meteor/client/components/AutocompletePopup/ComposerBoxPopup.tsx
  • apps/meteor/client/components/AutocompletePopup/editableTextAdapter.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useComposerBoxPopupQueries.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useEnablePopupPreview.ts
  • apps/meteor/client/components/AutocompletePopup/index.ts
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.spec.tsx
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.tsx
  • apps/meteor/client/views/room/composer/ComposerBoxPopupEmoji.tsx
  • apps/meteor/client/views/room/composer/ComposerBoxPopupPreview.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.spec.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
  • apps/meteor/client/views/room/composer/messageBox/MessageBox.tsx
  • apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
  • apps/meteor/tests/e2e/page-objects/fragments/composer.ts
💤 Files with no reviewable changes (1)
  • apps/meteor/client/views/room/composer/ComposerBoxPopupEmoji.tsx
✅ Files skipped from review due to trivial changes (2)
  • apps/meteor/client/components/AutocompletePopup/index.ts
  • apps/meteor/client/components/AutocompletePopup/AutocompletePopupOption.ts
🚧 Files skipped from review as they are similar to previous changes (8)
  • apps/meteor/tests/e2e/page-objects/fragments/composer.ts
  • apps/meteor/client/views/room/composer/ComposerBoxPopupPreview.tsx
  • apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
  • apps/meteor/client/views/room/composer/messageBox/MessageBox.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.spec.tsx
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.spec.tsx
📜 Review details
⏰ 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). (4)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: Hacktron Security Check
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/components/AutocompletePopup/hooks/useEnablePopupPreview.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useComposerBoxPopupQueries.ts
  • apps/meteor/client/components/AutocompletePopup/editableTextAdapter.ts
  • apps/meteor/client/components/AutocompletePopup/ComposerBoxPopup.tsx
  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
🧠 Learnings (6)
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/components/AutocompletePopup/hooks/useEnablePopupPreview.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useComposerBoxPopupQueries.ts
  • apps/meteor/client/components/AutocompletePopup/editableTextAdapter.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.

Applied to files:

  • apps/meteor/client/components/AutocompletePopup/hooks/useEnablePopupPreview.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useComposerBoxPopupQueries.ts
  • apps/meteor/client/components/AutocompletePopup/editableTextAdapter.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/client/components/AutocompletePopup/hooks/useEnablePopupPreview.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useComposerBoxPopupQueries.ts
  • apps/meteor/client/components/AutocompletePopup/editableTextAdapter.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/client/components/AutocompletePopup/hooks/useEnablePopupPreview.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useComposerBoxPopupQueries.ts
  • apps/meteor/client/components/AutocompletePopup/editableTextAdapter.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/client/components/AutocompletePopup/hooks/useEnablePopupPreview.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useComposerBoxPopupQueries.ts
  • apps/meteor/client/components/AutocompletePopup/editableTextAdapter.ts
  • apps/meteor/client/components/AutocompletePopup/ComposerBoxPopup.tsx
  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • apps/meteor/client/components/AutocompletePopup/ComposerBoxPopup.tsx
  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
🪛 ast-grep (0.43.0)
apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts

[warning] 97-97: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^| |\n)(${option.trigger})([^\\s]*$))
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 97-97: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^)(${option.trigger})([^\\s]*$))
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 125-125: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^| |\n)(${trigger})[^\\s]*$)
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 125-125: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^)(${trigger})[^\\s]*$)
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 143-143: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^| |\n)(${option.trigger})([^\\s]*$))
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 143-143: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^)(${option.trigger})([^\\s]*$))
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)

🔇 Additional comments (7)
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx (2)

310-328: Fix type safety: enablePreviewQuery parameter should match filter shape.

The type cast (filter as any)?.cmd on line 314 indicates that the enablePreviewQuery callback's filter parameter type doesn't include the cmd property, even though getItemsFromLocal (line 315) correctly expects { cmd: string; params: string; tmid: string }. Both callbacks should receive the same typed filter parameter.


161-187: Remove as any type cast and provide explicit typing.

The as any cast on line 187 violates the TypeScript accuracy guideline. Determine the correct return type for createAutocompletePopupConfig<ComposerBoxPopupRoomProps> and remove the cast to achieve proper type safety.

apps/meteor/client/components/AutocompletePopup/editableTextAdapter.ts (1)

1-34: LGTM!

apps/meteor/client/components/AutocompletePopup/ComposerBoxPopup.tsx (1)

9-34: LGTM!

Also applies to: 55-56, 85-85, 118-118

apps/meteor/client/components/AutocompletePopup/hooks/useComposerBoxPopupQueries.ts (1)

5-36: LGTM!

apps/meteor/client/components/AutocompletePopup/hooks/useEnablePopupPreview.ts (1)

1-4: LGTM!

apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts (1)

1-57: LGTM!

Also applies to: 69-157, 174-290

@ricardogarim ricardogarim changed the title refactor: extract composer autocomplete engine to ui-client refactor: extract composer autocomplete to a new component Jun 19, 2026
@ricardogarim ricardogarim marked this pull request as ready for review June 19, 2026 12:38

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 issues found across 17 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/meteor/client/components/AutocompletePopup/editableTextAdapter.ts Outdated
Comment thread apps/meteor/client/components/AutocompletePopup/editableTextAdapter.ts Outdated

@MartinSchoeler MartinSchoeler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it possible to break down this PR into at least 2 parts, the refactor and the move? The way it is today is kinda hard to review, and since the component being refactored is already used in a important part of the UI, it would be better to be more cautious.

@ricardogarim ricardogarim modified the milestones: 8.6.0, 8.7.0 Jun 19, 2026
@tassoevan tassoevan force-pushed the refactor/composer-autocomplete-engine branch from 862f80f to 7d23517 Compare June 19, 2026 22:28

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts`:
- Around line 202-204: The item comparison in useAutocompletePopup uses
inconsistent methods: lines 202 and 221 use reference equality (item ===
focused) while line 83 correctly uses ID comparison (item._id === focused?._id).
Replace the reference equality checks with ID-based comparison (item._id ===
focused?._id) in both the findIndex call at line 202 and the similar comparison
at line 221 to ensure consistent behavior and prevent navigation issues when
query results return new object references.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 60b1d492-ee03-4cac-9728-1c0eebdb86ee

📥 Commits

Reviewing files that changed from the base of the PR and between 862f80f and 7d23517.

📒 Files selected for processing (17)
  • apps/meteor/client/components/AutocompletePopup/AutocompletePopupOption.ts
  • apps/meteor/client/components/AutocompletePopup/ComposerBoxPopup.tsx
  • apps/meteor/client/components/AutocompletePopup/editableTextAdapter.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useComposerBoxPopupQueries.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useEnablePopupPreview.ts
  • apps/meteor/client/components/AutocompletePopup/index.ts
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.spec.tsx
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.tsx
  • apps/meteor/client/views/room/composer/ComposerBoxPopupEmoji.tsx
  • apps/meteor/client/views/room/composer/ComposerBoxPopupPreview.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.spec.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
  • apps/meteor/client/views/room/composer/messageBox/MessageBox.tsx
  • apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
  • apps/meteor/tests/e2e/page-objects/fragments/composer.ts
💤 Files with no reviewable changes (1)
  • apps/meteor/client/views/room/composer/ComposerBoxPopupEmoji.tsx
✅ Files skipped from review due to trivial changes (2)
  • apps/meteor/client/components/AutocompletePopup/index.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useEnablePopupPreview.ts
🚧 Files skipped from review as they are similar to previous changes (13)
  • apps/meteor/client/components/AutocompletePopup/editableTextAdapter.ts
  • apps/meteor/client/views/room/composer/ComposerBoxPopupPreview.tsx
  • apps/meteor/client/components/AutocompletePopup/AutocompletePopupOption.ts
  • apps/meteor/client/components/AutocompletePopup/hooks/useComposerBoxPopupQueries.ts
  • apps/meteor/tests/e2e/page-objects/fragments/composer.ts
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.spec.tsx
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.ts
  • apps/meteor/client/views/room/composer/hooks/useComposerBoxPopup.spec.tsx
  • apps/meteor/client/views/room/contexts/ComposerPopupContext.ts
  • apps/meteor/client/components/AutocompletePopup/ComposerBoxPopup.tsx
  • apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.tsx
  • apps/meteor/client/views/room/composer/messageBox/MessageBox.tsx
  • apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
📜 Review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: Hacktron Security Check
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
🧠 Learnings (5)
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.

Applied to files:

  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts
🪛 ast-grep (0.43.0)
apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts

[warning] 97-97: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^| |\n)(${option.trigger})([^\\s]*$))
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 97-97: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^)(${option.trigger})([^\\s]*$))
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 125-125: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^| |\n)(${trigger})[^\\s]*$)
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 125-125: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^)(${trigger})[^\\s]*$)
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 143-143: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^| |\n)(${option.trigger})([^\\s]*$))
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)


[warning] 143-143: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp((?:^)(${option.trigger})([^\\s]*$))
Note: [CWE-1333] Inefficient Regular Expression Complexity

(regexp-from-variable)

🔇 Additional comments (5)
apps/meteor/client/components/AutocompletePopup/hooks/useAutocompletePopup.ts (5)

158-173: Stale option used after state update in handleKeyUp.

This issue was already flagged in a previous review. setOptionByInput() updates optionIndex state and returns the new option, but lines 163–167 still reference the stale option variable derived from the old state. Use the return value from setOptionByInput() for the ESC check.


1-50: LGTM!


52-85: LGTM!


87-149: LGTM!


233-290: LGTM!

@ricardogarim ricardogarim force-pushed the refactor/composer-autocomplete-engine branch from 7d23517 to c6af479 Compare June 23, 2026 11:39
@ricardogarim ricardogarim changed the base branch from develop to refactor/autocomplete-move June 23, 2026 11:40
@ricardogarim ricardogarim marked this pull request as draft June 23, 2026 12:28
@ricardogarim ricardogarim changed the title refactor: extract composer autocomplete to a new component refactor: decouple autocomplete engine via EditableTextAdapter Jun 23, 2026
@ricardogarim ricardogarim force-pushed the refactor/autocomplete-move branch from a6eecf2 to 9159c5d Compare June 23, 2026 12:59
@ricardogarim ricardogarim force-pushed the refactor/composer-autocomplete-engine branch from c6af479 to 2bdb4bb Compare June 23, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: chore type: feature Pull requests that introduces new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants