UiKit modal and contextual bar remount on every re-render, typed input is lost

Open Beginner friendly
#1,471 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Jaivansh-777 is already working on this.

Since Nov 28, 2026.

  • #1472 by @Jaivansh-777 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript, react
Domain
frontend

Research direction

The bad key is on UiKitModal in packages/react/src/views/ChatBody/ChatBody.js (around line 440) and on UiKitContextualBar in packages/react/src/views/ChatLayout/ChatLayout.js (around line 173). Confirm that the view data objects carry a stable id, then replace Math.random() with that id. Done when typed text in a modal or contextual bar survives a new message re-rendering the room.

Written by the indexing model from the issue text.

Description

Description:

UiKitModal and UiKitContextualBar are rendered with a random key:

  • packages/react/src/views/ChatBody/ChatBody.js:440: <UiKitModal key={Math.random()} initialView={uiKitModalData} />
  • packages/react/src/views/ChatLayout/ChatLayout.js:173: <UiKitContextualBar key={Math.random()} ... />

Because the key changes on every render, React unmounts and remounts the surface whenever the parent re-renders (a new message arrives, the typing indicator updates, scroll state changes). Anything the user typed into an app's modal or contextual bar is lost and the surface state is reset.

Steps to reproduce:
  1. Install a Rocket.Chat app that opens a UIKit modal (or contextual bar) with a text input.
  2. Open it from EmbeddedChat and start typing in the input.
  3. While it is open, have another user send a message in the room (anything that re-renders ChatBody / ChatLayout).
  4. The modal remounts and the typed text is gone.
Expected behavior:

The modal / contextual bar keeps its state until the view itself changes.

Actual behavior:

The surface is remounted on every parent re-render and loses its input.

Suggested fix: use a stable key, the view id (key={uiKitModalData?.id} and key={uiKitContextualBarData?.id}). I'd be happy to open a PR for this.

Dominant language
JavaScript
Stars
171
Forks
421
Avg merge
3d 6h
Merged PRs (30d)
4

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from RocketChat/EmbeddedChat

All issues in RocketChat/EmbeddedChat

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.