RocketChat / RocketChat/Rocket.Chat
Remove setState usage in componentDidMount for Menu popover
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 46.1k
- Forks
- 13.9k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 130
Description
Description
The PopoverMenuWrapper component in the Livechat Menu uses setState inside componentDidMount, with an explicit eslint disable:
// eslint-disable-next-line react/no-did-mount-set-state
this.setState({
position: { left, right, top, bottom },
placement,
});
Calling setState in componentDidMount is a known React anti-pattern and introduces an extra render cycle. The eslint disable suggests this is acknowledged technical debt.
Proposed Solution
Refactor PopoverMenuWrapper from a class component to a functional component and replace the lifecycle logic with useLayoutEffect, which is more appropriate for synchronous DOM measurements.
Key points:
- Use
useLayoutEffectfor layout-dependent calculations - Preserve existing behavior and public API
- Remove the eslint disable comment
- Keep the ref typed as
HTMLDivElement
Expected Impact
- Eliminates a React anti-pattern
- Removes lint suppression
- Aligns with the project’s ongoing migration toward functional components
- No behavioral or visual changes
Notes
I can open a PR with this refactor.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the TypeScript PopoverMenuWrapper component in the Livechat Menu and read its componentDidMount logic, ref handling, and public API. Refactor the layout measurement while preserving behavior, remove the eslint disable, and verify that linting and existing component checks pass without visual changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100