From 53a7e216cd97e739c69d6bdb802d7c9c2fb89e41 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Wed, 4 Jun 2025 14:57:14 +0200 Subject: [PATCH 1/4] fix(react-components): use custom RefAttributes instead of React.RefAttributes --- packages/eslint-plugin/src/configs/react.js | 12 ++++ .../library/etc/react-migration-v8-v9.api.md | 2 +- .../components/Button/ActionButtonShim.tsx | 22 ++++--- .../src/components/Button/ButtonShim.tsx | 26 +++++---- .../components/Button/CompoundButtonShim.tsx | 7 ++- .../components/Button/DefaultButtonShim.tsx | 11 ++-- .../src/components/Button/MenuButtonShim.tsx | 57 ++++++++++--------- .../components/Button/PrimaryButtonShim.tsx | 11 ++-- .../components/Button/ToggleButtonShim.tsx | 30 +++++----- .../src/components/Button/shimButtonProps.tsx | 6 +- .../src/components/Checkbox/CheckboxShim.tsx | 9 ++- .../src/components/NavDrawer/useNavDrawer.ts | 4 +- .../etc/react-utilities.api.md | 2 +- .../src/compose/getIntrinsicElementProps.ts | 4 +- 14 files changed, 124 insertions(+), 79 deletions(-) diff --git a/packages/eslint-plugin/src/configs/react.js b/packages/eslint-plugin/src/configs/react.js index 2d58c4295cb6c..8c7cb3f6bf159 100644 --- a/packages/eslint-plugin/src/configs/react.js +++ b/packages/eslint-plugin/src/configs/react.js @@ -37,6 +37,18 @@ module.exports = { }, ], 'react-compiler/react-compiler': ['error'], + '@typescript-eslint/no-restricted-types': [ + 'error', + { + types: { + 'React.RefAttributes': { + message: + '`React.RefAttributes` is leaking string starting @types/react@18.2.61 creating invalid type contracts. Use `RefAttributes` from @fluentui/react-utilities instead', + fixWith: 'RefAttributes', + }, + }, + }, + ], }, overrides: [ // Enable rules requiring type info only for appropriate files/circumstances diff --git a/packages/react-components/react-migration-v8-v9/library/etc/react-migration-v8-v9.api.md b/packages/react-components/react-migration-v8-v9/library/etc/react-migration-v8-v9.api.md index 017cb6c9a017a..51b9b559b527d 100644 --- a/packages/react-components/react-migration-v8-v9/library/etc/react-migration-v8-v9.api.md +++ b/packages/react-components/react-migration-v8-v9/library/etc/react-migration-v8-v9.api.md @@ -42,7 +42,7 @@ export const brandWeb: BrandVariants; export const ButtonShim: React_2.ForwardRefExoticComponent>; // @public (undocumented) -export const CheckboxShim: React_2.ForwardRefExoticComponent & React_2.RefAttributes>; +export const CheckboxShim: React_2.ForwardRefExoticComponent>; // @public export type ColorVariants = { diff --git a/packages/react-components/react-migration-v8-v9/library/src/components/Button/ActionButtonShim.tsx b/packages/react-components/react-migration-v8-v9/library/src/components/Button/ActionButtonShim.tsx index c2c8d3e73589f..67705e36c0516 100644 --- a/packages/react-components/react-migration-v8-v9/library/src/components/Button/ActionButtonShim.tsx +++ b/packages/react-components/react-migration-v8-v9/library/src/components/Button/ActionButtonShim.tsx @@ -3,20 +3,24 @@ import * as React from 'react'; import type { IButtonProps } from '@fluentui/react'; import { Button } from '@fluentui/react-components'; +import type { RefAttributes } from '@fluentui/react-utilities'; import { shimButtonProps } from './shimButtonProps'; /** * Shims a v8 ActionButton to render a v9 Button */ -export const ActionButtonShim: React.ForwardRefExoticComponent> = - React.forwardRef((props, _ref) => { - const variantProps = { - ...props, - variantClassName: 'ms-Button--action ms-Button--command', - }; +export const ActionButtonShim: React.ForwardRefExoticComponent< + IButtonProps & + // eslint-disable-next-line @typescript-eslint/no-restricted-types -- this is expected in order to be compatible with v8, as every v8 interface contains `React.RefAttributes` to accept ref as string + React.RefAttributes +> = React.forwardRef((props, _ref) => { + const variantProps = { + ...props, + variantClassName: 'ms-Button--action ms-Button--command', + }; - const shimProps = shimButtonProps(variantProps); + const shimProps = shimButtonProps(variantProps); - return