Skip to content

chore: improve typing for ContextualbarResizable resize handler#38595

Open
TheRazorbill wants to merge 6 commits into
RocketChat:developfrom
TheRazorbill:fix/improve-header-and-contextualbar-typing
Open

chore: improve typing for ContextualbarResizable resize handler#38595
TheRazorbill wants to merge 6 commits into
RocketChat:developfrom
TheRazorbill:fix/improve-header-and-contextualbar-typing

Conversation

@TheRazorbill
Copy link
Copy Markdown
Contributor

@TheRazorbill TheRazorbill commented Feb 10, 2026

Proposed changes

This PR improves TypeScript type safety in ContextualbarResizable by refining the onResize handler implementation:

  • Extract resize handler into a named function (handleResize)
  • Type the handler explicitly using ResizeCallback from re-resizable
  • Remove the inline type cast (as ResizeCallback) and rely on TypeScript inference
  • Improve overall readability and maintainability

Instead of using an inline cast, we now define handleResize with an explicit ResizeCallback type.
This keeps the code cleaner and allows TypeScript to automatically infer the correct parameter types:

  • _e: MouseEvent | TouchEvent
  • _dir: Direction
  • elRef: HTMLElement

No runtime behavior changes — this is purely a typing and code quality improvement.

Issue(s)

Closes: #38759

Steps to test or reproduce

  • Run TypeScript checks locally
  • Ensure the UI builds successfully with no type errors

Example:

yarn lint
yarn test

Before

image

After

image

Summary by CodeRabbit

  • Refactor
    • Improved reliability and performance of contextual bar resizing by memoizing the resize handler for steadier width updates.
  • Chores
    • Added a patch release entry documenting the quality and type-safety improvement to the resizing logic.

Copilot AI review requested due to automatic review settings February 10, 2026 19:40
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Feb 10, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 10, 2026

🦋 Changeset detected

Latest commit: 932285e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 41 packages
Name Type
@rocket.chat/ui-client Patch
@rocket.chat/meteor Patch
@rocket.chat/gazzodown Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/livechat Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/http-router Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/models Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 10, 2026

No actionable comments were generated in the recent review. 🎉

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05b0171 and a32cd62.

📒 Files selected for processing (1)
  • packages/ui-client/src/components/Contextualbar/ContextualbarResizable.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/ui-client/src/components/Contextualbar/ContextualbarResizable.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer

Walkthrough

Extracts the inline resize callback in ContextualbarResizable into a named, typed handleResize (using ResizeCallback and useCallback) and wires it to onResize. Adds a patch changeset entry documenting the improvement; public API and props unchanged.

Changes

Cohort / File(s) Summary
Contextualbar resize logic
packages/ui-client/src/components/Contextualbar/ContextualbarResizable.tsx
Replaced inline anonymous resize handler with a named handleResize callback (typed as ResizeCallback, wrapped with useCallback). Handler updates contextualbarWidth from the element's style.width; default/min/max sizing preserved.
Release changeset
.changeset/rotten-hounds-destroy.md
Added a patch changeset entry describing the type-safety and performance improvement for the ContextualbarResizable resize handler (no code changes).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A tiny refactor, light and bright,
handleResize hops in, tidy and right,
Typed and named, it stays the same tune,
Widths update smoothly beneath the moon,
A little rabbit winks at the new light!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: improve typing for ContextualbarResizable resize handler' directly and accurately describes the main change—improving TypeScript typing for the resize handler in ContextualbarResizable.
Linked Issues check ✅ Passed The PR successfully implements the key requirements from issue #38759: extracting the handler into a named function, adding explicit ResizeCallback typing, and using useCallback for performance optimization.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objectives. The modifications to ContextualbarResizable.tsx and the changeset file align perfectly with the goal of improving type safety and performance.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances TypeScript type safety in the ContextualbarResizable component by refactoring the resize event handler. Instead of using an inline anonymous function with manual type casts, the handler is now extracted into a named function with explicit ResizeCallback typing from the re-resizable library. This improves code readability, maintainability, and allows TypeScript to properly infer parameter types without manual casting.

Changes:

  • Extract inline resize handler into a named handleResize function
  • Add explicit ResizeCallback type annotation from re-resizable
  • Remove inline type casts in favor of TypeScript inference

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Extract resize handler to named function
- Type handler with ResizeCallback from re-resizable
- Remove type cast, let TypeScript infer parameter types
- Improve code readability and maintainability

Instead of inline cast 'as ResizeCallback', we now define handleResize
as a named function with explicit ResizeCallback type. This makes the code
cleaner and lets TypeScript automatically infer the correct types for all
parameters (_e: MouseEvent | TouchEvent, _dir: Direction, elRef: HTMLElement)
@TheRazorbill TheRazorbill force-pushed the fix/improve-header-and-contextualbar-typing branch from a415fe6 to 05b0171 Compare February 17, 2026 20:54
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/ui-client/src/components/Contextualbar/ContextualbarResizable.tsx (1)

22-27: Consider moving the type to the generic parameter rather than the variable annotation.

The current pattern const handleResize: ResizeCallback = useCallback(...) relies on contextual typing flowing from the variable annotation through useCallback's generic constraint (T extends Function) to type _e, _dir, and elRef. This works correctly in TypeScript 5.x, but placing the type as an explicit generic argument is more direct and makes the intent unambiguous:

The re-resizable source exports ResizeCallback as (event: MouseEvent | TouchEvent, direction: Direction, elementRef: HTMLElement, delta: NumberSize) => void, confirming elRef.style.width access is safe regardless of approach.

♻️ Suggested alternative for more explicit typing
-	const handleResize: ResizeCallback = useCallback(
+	const handleResize = useCallback<ResizeCallback>(
 		(_e, _dir, elRef) => {
 			setContextualbarWidth(elRef.style.width);
 		},
 		[setContextualbarWidth],
 	);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/ui-client/src/components/Contextualbar/ContextualbarResizable.tsx`
around lines 22 - 27, The handler's type should be applied as a generic to
useCallback instead of as a variable annotation; change the declaration of
handleResize so it uses useCallback<ResizeCallback>(...) (keeping the same
parameters and body that call setContextualbarWidth(elRef.style.width)) rather
than const handleResize: ResizeCallback = useCallback(...), referencing
ResizeCallback, useCallback, handleResize, setContextualbarWidth and
elRef.style.width to make the typing explicit and unambiguous.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74d8a6f and 05b0171.

📒 Files selected for processing (2)
  • .changeset/rotten-hounds-destroy.md
  • packages/ui-client/src/components/Contextualbar/ContextualbarResizable.tsx
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/ui-client/src/components/Contextualbar/ContextualbarResizable.tsx
🔇 Additional comments (3)
.changeset/rotten-hounds-destroy.md (1)

1-5: LGTM!

The patch-level bump is correct, and the description accurately reflects both the typing improvement and the minor memoization benefit introduced by useCallback.

packages/ui-client/src/components/Contextualbar/ContextualbarResizable.tsx (2)

4-6: LGTM!

import type for ResizeCallback is correct (erased at emit), and useCallback is properly sourced from react.


29-44: LGTM!

onResize={handleResize} placed after {...props} is consistent with the previous inline handler's position, preserving the intentional override of any caller-supplied onResize.

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/ui-client/src/components/Contextualbar/ContextualbarResizable.tsx`:
- Around line 22-27: The handler's type should be applied as a generic to
useCallback instead of as a variable annotation; change the declaration of
handleResize so it uses useCallback<ResizeCallback>(...) (keeping the same
parameters and body that call setContextualbarWidth(elRef.style.width)) rather
than const handleResize: ResizeCallback = useCallback(...), referencing
ResizeCallback, useCallback, handleResize, setContextualbarWidth and
elRef.style.width to make the typing explicit and unambiguous.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.68%. Comparing base (afaabea) to head (22ce868).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38595      +/-   ##
===========================================
+ Coverage    70.66%   70.68%   +0.01%     
===========================================
  Files         3191     3191              
  Lines       112965   112965              
  Branches     20451    20504      +53     
===========================================
+ Hits         79829    79846      +17     
+ Misses       31088    31069      -19     
- Partials      2048     2050       +2     
Flag Coverage Δ
e2e 60.38% <ø> (ø)
e2e-api 47.88% <ø> (+0.07%) ⬆️
unit 71.29% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TheRazorbill
Copy link
Copy Markdown
Contributor Author

Updates completed and tested.
Requesting review to confirm everything is good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ContextualbarResizable: Improve resize handler typing and performance

2 participants