Skip to content

refactor: extract composer autocomplete engine to ui-client#40925

Open
ricardogarim wants to merge 1 commit into
developfrom
refactor/composer-autocomplete-engine
Open

refactor: extract composer autocomplete engine to ui-client#40925
ricardogarim wants to merge 1 commit into
developfrom
refactor/composer-autocomplete-engine

Conversation

@ricardogarim

@ricardogarim ricardogarim commented Jun 11, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

Moves the message composer's autocomplete to @rocket.chat/ui-client with no behavior change, so other inputs can reuse it. It was coupled to ChatContext/ChatAPI; now text access is injected (EditableTextAdapter), so the composer plugs in chat.composer and any plain input plugs in the provided fromInputElement helper.

Before (apps/meteor) After
ComposerBoxPopup.tsx ui-client components/AutocompletePopup
useComposerBoxPopup.ts + useComposerBoxPopupQueries.ts + useEnablePopupPreview.ts ui-client hooks/useAutocompletePopup.ts
ComposerPopupOption + createMessageBoxPopupConfig ui-client AutocompletePopupOption + createAutocompletePopupConfig
emoji : config inline in ComposerPopupProvider.tsx client/components/EmojiAutocomplete/emojiPopupConfig.tsx (stays in apps/meteor - depends on emoji.list)

The engine is trigger-agnostic: it takes an array of configs and an adapter. Only the emoji config is extracted to a shared module - it's what the next consumer needs and the only one not room-coupled; the other five triggers (@, #, +:, /, !) stay inline in ComposerPopupProvider. The popup's e2e selector was renamed (ComposerBoxPopup -> AutocompletePopup) and the composer page object updated.

Tests were added for the popup behavior (useComposerBoxPopup.spec.tsx) and for the shared emoji config (emojiPopupConfig.spec.tsx).

Issue(s)

PRES-30

Steps to test or reproduce

Further comments

First planned consumer: emoji autocomplete in the custom status modal (follow-up PR).

Summary by CodeRabbit

  • New Features

    • Improved emoji autocomplete search with case-insensitive matching, smart ranking of exact and prefix matches, and recent emoji boosting.
    • Standardized autocomplete popup behavior across mentions, channels, emoji, commands, and canned responses.
  • Bug Fixes

    • Fixed skin-tone variant visibility in emoji suggestions based on query input.
  • Refactor

    • Consolidated internal autocomplete popup architecture for consistency and maintainability.

@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

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

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

Walkthrough

This PR refactors the composer autocomplete system from composer-specific components to a new generic autocomplete infrastructure in the UI client package, then migrates all popup triggers (people, channels, emoji, canned responses, commands) to use the new configuration-driven approach.

Changes

Autocomplete Infrastructure and Migration

Layer / File(s) Summary
Core autocomplete popup hook and infrastructure
packages/ui-client/src/hooks/useAutocompletePopup.ts, packages/ui-client/src/hooks/index.ts
Introduces useAutocompletePopup hook that manages trigger detection, item filtering/sorting, focus navigation, and keyboard event handling. Exports AutocompletePopupOption, EditableTextAdapter, createAutocompletePopupConfig, fromInputElement, useEnablePopupPreview, and useAutocompletePopupQueries utilities that drive autocomplete behavior from editor state and React Query results.
AutocompletePopup component and exports
packages/ui-client/src/components/AutocompletePopup/AutocompletePopup.tsx, packages/ui-client/src/components/AutocompletePopup/index.ts, packages/ui-client/src/components/index.ts
Renames ComposerBoxPopup to AutocompletePopup and updates its props type contract. Adds barrel exports so consumers can import the component and hook from @rocket.chat/ui-client.
Emoji autocomplete configuration
apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.tsx, apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.spec.tsx
Exports createEmojiPopupConfig that configures the : trigger to filter emoji from emoji.list, rank exact/prefix matches above substring matches, and boost recently-used emojis; hides tone variants unless the query includes a tone. Includes AutocompletePopupEmoji renderer and comprehensive tests validating search, ranking, recency, and variant behavior.
Composer hook refactoring and context updates
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
Simplifies useComposerBoxPopup to wrap useAutocompletePopup, removing 270+ lines of local keyboard/focus/filter/query logic. Refactors ComposerPopupContext to use AutocompletePopupOption[] and removes old composer-specific popup type definitions. Adds comprehensive tests covering trigger extraction, keyboard navigation, selection, and escape behavior.
Popup provider migration to autocomplete config
apps/meteor/client/views/room/providers/ComposerPopupProvider.tsx
Migrates all five popup triggers (@ people, # channels, : emoji, ! canned responses, / slash commands) to use createAutocompletePopupConfig. Emoji items now map to { _id } only and render via AutocompletePopupEmoji. Adds enablePreviewQuery predicate to conditionally enable preview requests based on command providesPreview metadata.
Popup consumer migrations and test updates
apps/meteor/client/views/room/composer/messageBox/MessageBox.tsx, apps/meteor/client/views/room/composer/ComposerBoxPopupPreview.tsx, apps/meteor/tests/e2e/page-objects/fragments/composer.ts
Updates MessageBox.tsx to import and render AutocompletePopup instead of ComposerBoxPopup. Updates ComposerBoxPopupPreview.tsx props type to use AutocompletePopupProps. E2E tests update selectors to target [name="AutocompletePopup"].

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested labels

type: feature

Suggested reviewers

  • ggazzo
  • tassoevan
🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main refactoring: extracting the composer's autocomplete engine to the ui-client shared package for reuse, which aligns with the comprehensive changeset.
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.

✏️ 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 and usage tips.

@ricardogarim ricardogarim force-pushed the refactor/composer-autocomplete-engine branch from 0938c32 to f6ed427 Compare June 11, 2026 23:59
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.21569% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.07%. Comparing base (a6bebd2) to head (f6ed427).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #40925      +/-   ##
===========================================
+ Coverage    70.04%   70.07%   +0.02%     
===========================================
  Files         3355     3352       -3     
  Lines       129162   129086      -76     
  Branches     22372    22296      -76     
===========================================
- Hits         90474    90452      -22     
+ Misses       35396    35349      -47     
+ Partials      3292     3285       -7     
Flag Coverage Δ
e2e 59.19% <79.06%> (-0.13%) ⬇️
e2e-api 47.04% <ø> (+0.77%) ⬆️
unit 69.98% <88.77%> (+0.04%) ⬆️

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
@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

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.tsx">

<violation number="1" location="apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.tsx:49">
P2: Recent emoji ranking is reversed: older recents are prioritized over newer ones.</violation>
</file>

<file name="packages/ui-client/src/hooks/useAutocompletePopup.ts">

<violation number="1" location="packages/ui-client/src/hooks/useAutocompletePopup.ts:106">
P2: Server autocomplete query can run prematurely on filter changes because `counter` reset happens after render.</violation>
</file>

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

Re-trigger cubic

let bScore = bExact + bPartial;

if (recents.includes(a._id)) {
aScore += recents.indexOf(a._id) + 1;

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.

P2: Recent emoji ranking is reversed: older recents are prioritized over newer ones.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/meteor/client/components/EmojiAutocomplete/emojiPopupConfig.tsx, line 49:

<comment>Recent emoji ranking is reversed: older recents are prioritized over newer ones.</comment>

<file context>
@@ -0,0 +1,84 @@
+				let bScore = bExact + bPartial;
+
+				if (recents.includes(a._id)) {
+					aScore += recents.indexOf(a._id) + 1;
+				}
+				if (recents.includes(b._id)) {
</file context>
Suggested change
aScore += recents.indexOf(a._id) + 1;
aScore += recents.length - recents.indexOf(a._id);

placeholderData: keepPreviousData,
queryKey: ['message-popup', 'server', filter, popup],
queryFn: () => popup?.getItemsFromServer?.(filter) || [],
enabled: counter > 0,

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.

P2: Server autocomplete query can run prematurely on filter changes because counter reset happens after render.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/ui-client/src/hooks/useAutocompletePopup.ts, line 106:

<comment>Server autocomplete query can run prematurely on filter changes because `counter` reset happens after render.</comment>

<file context>
@@ -0,0 +1,403 @@
+				placeholderData: keepPreviousData,
+				queryKey: ['message-popup', 'server', filter, popup],
+				queryFn: () => popup?.getItemsFromServer?.(filter) || [],
+				enabled: counter > 0,
+			},
+		],
</file context>

@ricardogarim ricardogarim added this to the 8.6.0 milestone Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Pull requests that introduces new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant