Skip to content

fix(markups): guard UserMention against missing MarkupInteractionContext - #1483

Open
swarnendusahu10-dotcom wants to merge 1 commit into
RocketChat:developfrom
swarnendusahu10-dotcom:fix/issue-1482-user-mention-missing-context-crash
Open

swarnendusahu10-dotcom wants to merge 1 commit into
RocketChat:developfrom
swarnendusahu10-dotcom:fix/issue-1482-user-mention-missing-context-crash

Conversation

@swarnendusahu10-dotcom

Copy link
Copy Markdown
Contributor

Summary

Fixes #1482

Problem

Scrolling up to load older messages containing UIKit blocks with @mentions crashes EmbeddedChat to a blank white screen with:
Uncaught TypeError: Cannot read properties of undefined (reading 'members')

  • FuselageSurfaceRenderer (in @embeddedchat/ui-kit) renders <Markup> for mrkdwn text without wrapping it in <MarkupInteractionContext.Provider>.
  • MarkupInteractionContext was initialized with createContext() (undefined default).
  • UserMention destructured { members, username } directly from useContext(MarkupInteractionContext), throwing a TypeError whenever the provider was absent.

Changes

  • packages/markups/src/MarkupInteractionContext.js:
    • Added a safe default context value { members: [], username: '' } to createContext(...).
  • packages/markups/src/mentions/UserMention.js:
    • Added defensive || {} fallback when destructuring MarkupInteractionContext and RCContext (handles explicit undefined/null provider values).
    • Guarded hasMember against null / non-object members and null member entries using Object.values(members).some((member) => member?.username === user).
    • Guarded handleUserInfo with optional chaining (RCInstance?.userData), data?.user check, and try/catch.
    • Guarded tooltipMap so an empty username does not collide with empty values, and used optional chaining on contents?.value.
  • .changeset/fix-user-mention-missing-context.md: Added patch changeset for @embeddedchat/markups.

Verification

  • ESLint on all modified files: 0 errors, 0 warnings.
  • @embeddedchat/markups Rollup build (yarn build): exited cleanly with code 0.

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.

Bug: White screen crash (Cannot read properties of undefined (reading 'members')) when rendering UserMention outside MarkupInteractionContext

1 participant