Skip to content

Commit b3bb63e

Browse files
authored
feat: support React 19 in peerDependencies (#393)
1 parent c4fd8b8 commit b3bb63e

18 files changed

Lines changed: 35 additions & 23 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@
120120
},
121121
"peerDependencies": {
122122
"@gravity-ui/uikit": "^7.39.0",
123-
"react": "^16.14.0 || ^17.0.0 || ^18.0.0",
124-
"react-dom": "^16.14.0 || ^17.0.0 || ^18.0.0"
123+
"react": "^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
124+
"react-dom": "^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
125125
},
126126
"nano-staged": {
127127
"*.{scss}": [

src/components/ChangelogDialog/ChangelogDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function ChangelogDialog(props: ChangelogDialogProps) {
5757
className,
5858
} = props;
5959

60-
const idRef = React.useRef<number>();
60+
const idRef = React.useRef<number | undefined>(undefined);
6161
idRef.current = idRef.current || getNextId();
6262
const dialogCaptionId = `changelog-dialog-title-${idRef.current}`;
6363

src/components/DelayedTextInput/hooks/useDelayedValue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function useDelayedValue<TValue = unknown>(
1919
) {
2020
const [currentValue, setCurrentValue] = React.useState<TValue>(value);
2121

22-
const timeoutRef = React.useRef<number>();
22+
const timeoutRef = React.useRef<number | undefined>(undefined);
2323

2424
const delayedOnChange = React.useCallback(
2525
(nextValue: TValue) => {

src/components/Gallery/Gallery.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export const Gallery = ({
4242
const items = children ? React.Children.map(children, (child) => child.props) : emptyItems;
4343
const itemsCount = items.length;
4444

45-
const [itemRefs, setItemRefs] = React.useState<React.RefObject<HTMLButtonElement>[]>(() =>
46-
items.map(() => React.createRef()),
45+
const [itemRefs, setItemRefs] = React.useState<React.RefObject<HTMLButtonElement | null>[]>(
46+
() => items.map(() => React.createRef()),
4747
);
4848

4949
const [hiddenHeader, setHiddenHeader] = React.useState(false);
@@ -188,9 +188,15 @@ export const Gallery = ({
188188

189189
const selected = activeItemIndex === index;
190190

191+
// Narrows RefObject<T | null> back to RefObject<T>
192+
// for compatibility with @types/react@18 LegacyRef typing.
193+
const buttonRef = itemRefs[
194+
index
195+
] as React.RefObject<HTMLButtonElement>;
196+
191197
return (
192198
<button
193-
ref={itemRefs[index]}
199+
ref={buttonRef}
194200
type="button"
195201
key={index}
196202
onClick={handleClick}

src/components/Gallery/hooks/useNavigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22

33
export type UseNavigationProps = {
44
initialItemIndex?: number;
5-
itemRefs: React.RefObject<HTMLButtonElement>[];
5+
itemRefs: React.RefObject<HTMLButtonElement | null>[];
66
};
77

88
export function useNavigation({initialItemIndex = 0, itemRefs}: UseNavigationProps) {

src/components/Notification/Notification.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import './Notification.scss';
1212
const b = block('notification');
1313

1414
type Props = {
15-
wrapperRef?: React.RefObject<HTMLDivElement>;
15+
wrapperRef?: React.RefObject<HTMLDivElement | null>;
1616
notification: NotificationProps;
1717
};
1818

src/components/Notification/NotificationWithSwipe.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const swipeActionContainerCls = b('swipe-action-container');
1717
type Props = {
1818
notification: NotificationProps;
1919
swipeThreshold?: number;
20-
wrapperRef?: React.RefObject<HTMLDivElement>;
20+
wrapperRef?: React.RefObject<HTMLDivElement | null>;
2121
};
2222

2323
export const NotificationWithSwipe = React.memo(function NotificationWithSwipe(props: Props) {

src/components/Notification/definitions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type NotificationProps = {
2626
id: string;
2727
content:
2828
| React.ReactNode
29-
| ((props: {wrapperRef?: React.RefObject<HTMLDivElement>}) => React.ReactNode);
29+
| ((props: {wrapperRef?: React.RefObject<HTMLDivElement | null>}) => React.ReactNode);
3030

3131
title?: React.ReactNode;
3232
formattedDate?: React.ReactNode;

src/components/Notifications/Notifications.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const b = block('notifications');
1919
export const Notifications = React.memo(function Notifications(props: NotificationsProps) {
2020
const {t} = i18n.useTranslation();
2121

22-
let content: JSX.Element;
22+
let content: React.ReactElement;
2323

2424
const visibleNotificationsCount = props.notifications.filter((n) => !n.archived).length;
2525
const hasUnloadedNotifications =

0 commit comments

Comments
 (0)