Skip to content

Commit 804cc82

Browse files
authored
fix: react types backwards compat (#8099)
* fix: keep more compatible React component types * revert v3 explicit change * add react-aria components as well * fix remaining
1 parent 72fabca commit 804cc82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+88
-87
lines changed

packages/@react-aria/collections/src/CollectionBuilder.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ function useSSRCollectionNode<T extends Element>(Type: string, props: object, re
157157
return <Type ref={itemRef}>{children}</Type>;
158158
}
159159

160-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactNode;
161-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactNode;
162-
export function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactElement): (props: P & React.RefAttributes<any>) => ReactNode {
160+
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactElement | null;
161+
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactElement | null;
162+
export function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactElement): (props: P & React.RefAttributes<any>) => ReactElement | null {
163163
let Component = ({node}) => render(node.props, node.props.ref, node);
164164
let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {
165165
let focusableProps = useContext(FocusableContext);
@@ -190,7 +190,7 @@ export function createLeafComponent<P extends object, E extends Element>(type: s
190190
return Result;
191191
}
192192

193-
export function createBranchComponent<T extends object, P extends {children?: any}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement, useChildren: (props: P) => ReactNode = useCollectionChildren): (props: P & React.RefAttributes<E>) => ReactNode {
193+
export function createBranchComponent<T extends object, P extends {children?: any}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement, useChildren: (props: P) => ReactNode = useCollectionChildren): (props: P & React.RefAttributes<E>) => ReactElement | null {
194194
let Component = ({node}) => render(node.props, node.props.ref, node);
195195
let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {
196196
let children = useChildren(props);

packages/@react-aria/collections/src/Hidden.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import {forwardRefType} from '@react-types/shared';
14-
import React, {createContext, forwardRef, ReactElement, ReactNode, useContext} from 'react';
14+
import React, {createContext, forwardRef, JSX, ReactElement, ReactNode, useContext} from 'react';
1515

1616
// React doesn't understand the <template> element, which doesn't have children like a normal element.
1717
// It will throw an error during hydration when it expects the firstChild to contain content rendered
@@ -35,7 +35,7 @@ if (typeof HTMLTemplateElement !== 'undefined') {
3535

3636
export const HiddenContext = createContext<boolean>(false);
3737

38-
export function Hidden(props: {children: ReactNode}): ReactNode {
38+
export function Hidden(props: {children: ReactNode}): JSX.Element {
3939
let isHidden = useContext(HiddenContext);
4040
if (isHidden) {
4141
// Don't hide again if we are already hidden.

packages/@react-aria/focus/src/FocusRing.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import clsx from 'clsx';
1414
import {mergeProps} from '@react-aria/utils';
15-
import React, {ReactElement, ReactNode} from 'react';
15+
import React, {ReactElement} from 'react';
1616
import {useFocusRing} from './useFocusRing';
1717

1818
export interface FocusRingProps {
@@ -40,7 +40,7 @@ export interface FocusRingProps {
4040
* Focus rings are visible only when the user is interacting with a keyboard,
4141
* not with a mouse, touch, or other input methods.
4242
*/
43-
export function FocusRing(props: FocusRingProps): ReactNode {
43+
export function FocusRing(props: FocusRingProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>> {
4444
let {children, focusClass, focusRingClass} = props;
4545
let {isFocused, isFocusVisible, focusProps} = useFocusRing(props);
4646
let child = React.Children.only(children);

packages/@react-aria/i18n/src/context.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import {isRTL} from './utils';
1414
import {Locale, useDefaultLocale} from './useDefaultLocale';
15-
import React, {ReactNode, useContext} from 'react';
15+
import React, {JSX, ReactNode, useContext} from 'react';
1616

1717
export interface I18nProviderProps {
1818
/** Contents that should have the locale applied. */
@@ -26,7 +26,7 @@ const I18nContext = React.createContext<Locale | null>(null);
2626
/**
2727
* Provides the locale for the application to all child components.
2828
*/
29-
export function I18nProvider(props: I18nProviderProps): ReactNode {
29+
export function I18nProvider(props: I18nProviderProps): JSX.Element {
3030
let {locale, children} = props;
3131
let defaultLocale = useDefaultLocale();
3232

packages/@react-aria/i18n/src/server.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import type {LocalizedString} from '@internationalized/string';
14-
import React, {ReactNode} from 'react';
14+
import React, {JSX} from 'react';
1515

1616
type PackageLocalizedStrings = {
1717
[packageName: string]: Record<string, LocalizedString>
@@ -27,7 +27,7 @@ interface PackageLocalizationProviderProps {
2727
* A PackageLocalizationProvider can be rendered on the server to inject the localized strings
2828
* needed by the client into the initial HTML.
2929
*/
30-
export function PackageLocalizationProvider(props: PackageLocalizationProviderProps): ReactNode | null {
30+
export function PackageLocalizationProvider(props: PackageLocalizationProviderProps): JSX.Element | null {
3131
if (typeof document !== 'undefined') {
3232
console.log('PackageLocalizationProvider should only be rendered on the server.');
3333
return null;

packages/@react-aria/interactions/src/PressResponder.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {FocusableElement} from '@react-types/shared';
1414
import {mergeProps, useObjectRef, useSyncRef} from '@react-aria/utils';
1515
import {PressProps} from './usePress';
1616
import {PressResponderContext} from './context';
17-
import React, {ForwardedRef, ReactNode, useContext, useEffect, useMemo, useRef} from 'react';
17+
import React, {ForwardedRef, JSX, ReactNode, useContext, useEffect, useMemo, useRef} from 'react';
1818

1919
interface PressResponderProps extends PressProps {
2020
children: ReactNode
@@ -56,7 +56,7 @@ export const PressResponder = React.forwardRef(({children, ...props}: PressRespo
5656
);
5757
});
5858

59-
export function ClearPressResponder({children}: {children: ReactNode}): ReactNode {
59+
export function ClearPressResponder({children}: {children: ReactNode}): JSX.Element {
6060
let context = useMemo(() => ({register: () => {}}), []);
6161
return (
6262
<PressResponderContext.Provider value={context}>

packages/@react-aria/overlays/src/DismissButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import {AriaLabelingProps, DOMProps} from '@react-types/shared';
1414
// @ts-ignore
1515
import intlMessages from '../intl/*.json';
16-
import React, {ReactNode} from 'react';
16+
import React, {JSX} from 'react';
1717
import {useLabels} from '@react-aria/utils';
1818
import {useLocalizedStringFormatter} from '@react-aria/i18n';
1919
import {VisuallyHidden} from '@react-aria/visually-hidden';
@@ -28,7 +28,7 @@ export interface DismissButtonProps extends AriaLabelingProps, DOMProps {
2828
* users to dismiss a modal or popup when there is no visual
2929
* affordance to do so.
3030
*/
31-
export function DismissButton(props: DismissButtonProps): ReactNode {
31+
export function DismissButton(props: DismissButtonProps): JSX.Element {
3232
let {onDismiss, ...otherProps} = props;
3333
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/overlays');
3434

packages/@react-aria/overlays/src/Overlay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const OverlayContext = React.createContext<{contain: boolean, setContain:
4949
* A container which renders an overlay such as a popover or modal in a portal,
5050
* and provides a focus scope for the child elements.
5151
*/
52-
export function Overlay(props: OverlayProps): ReactNode | null {
52+
export function Overlay(props: OverlayProps): React.ReactPortal | null {
5353
let isSSR = useIsSSR();
5454
let {portalContainer = isSSR ? null : document.body, isExiting} = props;
5555
let [contain, setContain] = useState(false);

packages/@react-aria/overlays/src/PortalProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import React, {createContext, ReactNode, useContext} from 'react';
13+
import React, {createContext, JSX, ReactNode, useContext} from 'react';
1414

1515
export interface PortalProviderProps {
1616
/** Should return the element where we should portal to. Can clear the context by passing null. */
@@ -26,7 +26,7 @@ export const PortalContext = createContext<PortalProviderContextValue>({});
2626
/**
2727
* Sets the portal container for all overlay elements rendered by its children.
2828
*/
29-
export function UNSAFE_PortalProvider(props: PortalProviderProps): ReactNode {
29+
export function UNSAFE_PortalProvider(props: PortalProviderProps): JSX.Element {
3030
let {getContainer} = props;
3131
let {getContainer: ctxGetContainer} = useUNSAFE_PortalContext();
3232
return (

packages/@react-aria/overlays/src/useModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import {DOMAttributes} from '@react-types/shared';
14-
import React, {AriaAttributes, ReactNode, useContext, useEffect, useMemo, useState} from 'react';
14+
import React, {AriaAttributes, JSX, ReactNode, useContext, useEffect, useMemo, useState} from 'react';
1515
import ReactDOM from 'react-dom';
1616
import {useIsSSR} from '@react-aria/ssr';
1717
import {useUNSAFE_PortalContext} from './PortalProvider';
@@ -37,7 +37,7 @@ const Context = React.createContext<ModalContext | null>(null);
3737
* subtree from screen readers. This is done using React context in order to account for things
3838
* like portals, which can cause the React tree and the DOM tree to differ significantly in structure.
3939
*/
40-
export function ModalProvider(props: ModalProviderProps): ReactNode {
40+
export function ModalProvider(props: ModalProviderProps): JSX.Element {
4141
let {children} = props;
4242
let parent = useContext(Context);
4343
let [modalCount, setModalCount] = useState(0);
@@ -101,7 +101,7 @@ function OverlayContainerDOM(props: ModalProviderProps) {
101101
* if a modal or other overlay is opened. Only the top-most modal or
102102
* overlay should be accessible at once.
103103
*/
104-
export function OverlayProvider(props: ModalProviderProps): ReactNode {
104+
export function OverlayProvider(props: ModalProviderProps): JSX.Element {
105105
return (
106106
<ModalProvider>
107107
<OverlayContainerDOM {...props} />

0 commit comments

Comments
 (0)