Skip to content

fix(react): use a stable key for UiKit modal and contextual bar - #1472

Open
Jaivansh-777 wants to merge 1 commit into
RocketChat:developfrom
Jaivansh-777:fix/uikit-stable-key
Open

Jaivansh-777 wants to merge 1 commit into
RocketChat:developfrom
Jaivansh-777:fix/uikit-stable-key

Conversation

@Jaivansh-777

Copy link
Copy Markdown

Keep UiKit modal and contextual bar mounted across re-renders

Acceptance Criteria fulfillment

  • An open UiKit modal / contextual bar keeps typed input when ChatBody or ChatLayout re-renders
  • modal.update / contextual_bar.update changes are no longer lost to a remount
  • Opening a different view (new view id) still mounts a fresh surface

Fixes #1471

Changes

  • ChatBody.js: <UiKitModal key={Math.random()} /> -> key={uiKitModalData?.id}
  • ChatLayout.js: <UiKitContextualBar key={Math.random()} /> -> key={uiKitContextualBarData?.id}

useUiKitView keeps the view and form values in local state and receives updates through the emitter keyed by view.id, so a random key reset both on every parent re-render. Keying by the view id keeps the surface mounted for the same view and remounts it when a new view opens.

Video/Screenshots

I don't have a Rocket.Chat server with a UiKit app set up locally yet, so I'll check it on the PR preview once it's deployed and add before/after recordings here.

PR Test Details

  • eslint on the changed files: no errors
  • prettier --check: passes
  • npm run build in packages/react: passes

Note: The PR will be ready for live testing at https://rocketchat.github.io/EmbeddedChat/pulls/pr-<pr_number> after approval.

Both were keyed with Math.random(), so every parent re-render
remounted them and reset typed input and view updates. Key them
by the view id instead.

Fixes RocketChat#1471

This branch has not been deployed

No deployments
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.

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

1 participant