Skip to content

fix(marketplace): prevent TypeError on unhandled keys in ScreenshotCarouselAnchor#38935

Open
JatinSharma222 wants to merge 2 commits into
RocketChat:developfrom
JatinSharma222:fix/38892-marketplace-carousel-keyboard-handler
Open

fix(marketplace): prevent TypeError on unhandled keys in ScreenshotCarouselAnchor#38935
JatinSharma222 wants to merge 2 commits into
RocketChat:developfrom
JatinSharma222:fix/38892-marketplace-carousel-keyboard-handler

Conversation

@JatinSharma222
Copy link
Copy Markdown

@JatinSharma222 JatinSharma222 commented Feb 23, 2026

Closes #38927

What this PR does

Fixes a critical bug in the Marketplace screenshot carousel keyboard handler that caused an Uncaught TypeError: keysObject[key] is not a function whenever any key outside of ArrowLeft, ArrowRight, or Escape was pressed (e.g. A, Enter, Shift).

Changes

1. Guard clause on keyboard handler

The handler now checks if a mapping exists for the pressed key before invoking it. Unmapped keys are silently ignored with zero side effects.

// Before
keysObject[onKeyDownEvent.key](); // TypeError if key not in object

// After
const handler = keysObject[event.key];
if (!handler) return;
handler();

2. Conditional event listener

The document.addEventListener is now wrapped in a useEffect gated on viewCarousel, so the listener is only registered while the modal is open and cleaned up automatically when it closes.

useEffect(() => {
  if (!viewCarousel) return;
  document.addEventListener('keydown', handleKeyboardKey);
  return () => document.removeEventListener('keydown', handleKeyboardKey);
}, [viewCarousel, ...]);

3. Accessibility improvement

Changed the thumbnail trigger from a plain Box (div) to Box is='button' so it is natively focusable and activatable via Enter/Space for keyboard-only users.

Steps to reproduce the original bug

  1. Navigate to Marketplace and open any app with a screenshot gallery
  2. Open browser console (F12)
  3. Press any non-navigation key (e.g. A)
  4. Observe Uncaught TypeError: keysObject[key] is not a function

Testing

  • Verified all three fixes manually via Storybook
  • yarn prettier and yarn eslint --quiet pass with zero errors on the changed file

@JatinSharma222 JatinSharma222 requested a review from a team as a code owner February 23, 2026 15:04
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Feb 23, 2026

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 missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 23, 2026

🦋 Changeset detected

Latest commit: 030f43e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 41 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/http-router Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/models Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 1 file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] : Marketplace Screenshot Carousel logic crash and global key listener leak

1 participant