Skip to content

fix(react): add try/catch error handling and null guards in ChatHeader - #1428

Open
yashsarvaiya45 wants to merge 3 commits into
RocketChat:developfrom
yashsarvaiya45:fix/chatheader-incomplete-logout-state
Open

yashsarvaiya45 wants to merge 3 commits into
RocketChat:developfrom
yashsarvaiya45:fix/chatheader-incomplete-logout-state

Conversation

@yashsarvaiya45

@yashsarvaiya45 yashsarvaiya45 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Related #1427

Following commit 860718a on develop (which already handles handleLogout() on channel access errors and resets auth/channel state in finally), this PR focuses on hardening error handling and null safety in packages/react/src/views/ChatHeader/ChatHeader.js:

  • Wrapped RCInstance.channelInfo() in getChannelInfo and RCInstance.permissionInfo() / RCInstance.getChannelRoles() in setMessageAllowed inside try...catch blocks to prevent unhandled promise rejections on network or server errors.
  • Added null/truthiness guards (res && 'errorType' in res, res?.success) before reading response properties to avoid TypeError crashes when API responses are undefined or malformed.

Testing

  • Verified formatting with Prettier and confirmed all workspace lint checks pass (yarn lint).

@rohanesor

Copy link
Copy Markdown

Hi @yashsarvaiya45, two things I noticed while reading this:

  1. The first hunk removes dispatchToastMessage from handleLogout's useCallback deps, but handleLogout still calls it in its catch (added in 860718a), so this would leave a stale closure and trip react-hooks/exhaustive-deps. Looks like a leftover from the rebase.
  2. Since 860718a, handleLogout always resets messages, channel info and auth state in finally, so part of Bug: Incomplete logout leaves UI stuck in authenticated state when channel is missing or access is denied in ChatHeader.js #1427 may already be covered on develop. It might help to note what still reproduces there; the try/catch around channelInfo() / permissionInfo() still looks useful.

@yashsarvaiya45 yashsarvaiya45 changed the title fix(react): invoke handleLogout on channel access errors and add null guards in ChatHeader fix(react): add try/catch error handling and null guards in ChatHeader Nov 30, 2026
@yashsarvaiya45

Copy link
Copy Markdown
Contributor Author

Hi @rohanesor, thank you for the thorough review!

  1. I've restored dispatchToastMessage to handleLogout's useCallback dependency array so react-hooks/exhaustive-deps passes cleanly without stale closures.
  2. Since commit 860718a on develop already covers the handleLogout state reset on channel access errors, I've updated the PR title and description to focus specifically on the try/catch wrappers around channelInfo() / permissionInfo() and the response null guards (res && 'errorType' in res / res?.success) to prevent unhandled rejections and TypeError crashes on malformed/undefined API responses.

Ready for another look!

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.

2 participants