Skip to content

Conversation

@wo-o29
Copy link
Contributor

@wo-o29 wo-o29 commented Sep 21, 2025

This PR improves the useForkRef hook by refining the type of cleanupRef to always be a function, removing unnecessary type assertions on refs, and narrowing the instance parameter type in refEffect from Instance | null to Instance. These changes increase type safety and code clarity:

  • Changed cleanupRef type from void | (() => void) to () => void because it always holds a cleanup function.

  • Removed redundant as React.RefObject type assertions for cleaner, clearer code.

  • Narrowed refEffect's instance parameter type since null values are guarded before invocation.

  • I have followed (at least) the PR section of the contributing guide.

@mui-bot
Copy link

mui-bot commented Sep 21, 2025

Netlify deploy preview

https://deploy-preview-46967--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) 0B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against b3e0cb3

@wo-o29 wo-o29 changed the title refactor(useForkRef): tighten cleanupRef type and simplify ref typing [utils] refactor(useForkRef): tighten cleanupRef type and simplify ref typing Sep 21, 2025
@wo-o29 wo-o29 closed this Sep 21, 2025
@wo-o29 wo-o29 reopened this Sep 21, 2025
@zannager zannager added the package: utils Specific to the utils package. label Sep 22, 2025
@zannager zannager requested a review from DiegoAndai September 22, 2025 11:28
@zannager zannager added the internal Behind-the-scenes enhancement. Formerly called “core”. label Sep 23, 2025
@DiegoAndai DiegoAndai requested review from siriwatknp and removed request for DiegoAndai September 24, 2025 20:57
@ZeeshanTamboli ZeeshanTamboli changed the title [utils] refactor(useForkRef): tighten cleanupRef type and simplify ref typing [internal] refactor(useForkRef): tighten cleanupRef type and simplify ref typing Sep 27, 2025
@ZeeshanTamboli ZeeshanTamboli changed the title [internal] refactor(useForkRef): tighten cleanupRef type and simplify ref typing [internal] refactor useForkRef by tightening cleanupRef type and simplify ref typing Sep 27, 2025
@ZeeshanTamboli ZeeshanTamboli changed the title [internal] refactor useForkRef by tightening cleanupRef type and simplify ref typing [internal] Refactor useForkRef TS types by tightening cleanupRef type and simplify ref typing Sep 27, 2025
@ZeeshanTamboli ZeeshanTamboli changed the title [internal] Refactor useForkRef TS types by tightening cleanupRef type and simplify ref typing [internal] Refactor useForkRef TS types: tighten cleanupRef and simplify ref typing Sep 27, 2025
Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for the improvement!

@ZeeshanTamboli ZeeshanTamboli merged commit e98e41d into mui:master Sep 27, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Behind-the-scenes enhancement. Formerly called “core”. package: utils Specific to the utils package. typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants