Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] React 19 compatibility #605

Merged
merged 35 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e4b2791
Update dependencies
michaldudak Sep 12, 2024
f73b90c
Fix handling render props
michaldudak Sep 12, 2024
61442e7
Diry fixes of other unit tests
michaldudak Sep 12, 2024
a50c971
Dedupe
michaldudak Sep 12, 2024
532b7c7
Add reactVersion utility
michaldudak Sep 13, 2024
18cd409
Fix ref type issues
michaldudak Sep 13, 2024
fba6e6a
Fix other TS errors
michaldudak Sep 13, 2024
8e9cb19
Fix reactVersion
michaldudak Sep 13, 2024
a3468ad
Use React.version
michaldudak Sep 13, 2024
22302ba
Dedupe
michaldudak Sep 13, 2024
a48cf6c
Disable next worker threads
michaldudak Sep 13, 2024
3f47481
Fix Positioner's anchor prop
michaldudak Sep 13, 2024
6e13642
Wrap GA in NoSsr
michaldudak Sep 13, 2024
08c4972
Merge remote-tracking branch 'upstream/master' into react-19-compatib…
michaldudak Sep 17, 2024
a71517d
Dedupe
michaldudak Sep 17, 2024
c1c2f41
Fix TS error
michaldudak Sep 17, 2024
10978a0
Maintain compatibility with React 18
michaldudak Sep 17, 2024
ddb980c
Clean up
michaldudak Sep 17, 2024
7690aad
Refactor useRenderPropForkRef
michaldudak Sep 17, 2024
76e7adb
Reduce the use of ReactElement<any>
michaldudak Sep 17, 2024
3e174c8
Remove the use of ReactElement<any>
michaldudak Sep 17, 2024
9b037d0
Remove @ts-ignore
michaldudak Sep 17, 2024
0544b4e
Deps
michaldudak Sep 18, 2024
75f56af
Merge remote-tracking branch 'upstream/master' into react-19-compatib…
michaldudak Sep 18, 2024
26c88a1
Merge remote-tracking branch 'upstream/master' into react-19-compatib…
michaldudak Sep 20, 2024
e1403e9
getInertValue
michaldudak Sep 20, 2024
2c00014
Merge remote-tracking branch 'upstream/master' into react-19-compatib…
michaldudak Sep 30, 2024
82dc038
Merge remote-tracking branch 'upstream/master' into react-19-compatib…
michaldudak Sep 30, 2024
669c720
Fix type error
michaldudak Sep 30, 2024
53fc104
Merge remote-tracking branch 'upstream/master' into react-19-compatib…
michaldudak Oct 1, 2024
0ecf2d3
Explain ts-expect-error
michaldudak Oct 2, 2024
d0176ba
Merge remote-tracking branch 'upstream/master' into react-19-compatib…
michaldudak Oct 2, 2024
a4b8623
Revert React and Next versions
michaldudak Oct 2, 2024
9cf306e
Fix TS error
michaldudak Oct 3, 2024
50020eb
Revert lockfile
michaldudak Oct 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/app/experiments/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function ReactSpringDialogDemo({ animated, keepMounted, modal, dismissible }: De
);
}

function ReactSpringTransition(props: { open: boolean; children?: React.ReactElement }) {
function ReactSpringTransition(props: { open: boolean; children?: React.ReactElement<unknown> }) {
const { open, children } = props;

const api = useSpringRef();
Expand Down Expand Up @@ -179,6 +179,7 @@ function ReactSpringTransition(props: { open: boolean; children?: React.ReactEle
}, [api, open, mounted, setMounted]);

return mounted ? (
/* @ts-ignore */
aarongarciah marked this conversation as resolved.
Show resolved Hide resolved
<springAnimated.div style={springs} className={classes.springWrapper}>
{children}
</springAnimated.div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { styled } from '@mui/system';
export default function UnstyledTooltipFollowCursor() {
return (
<div style={{ display: 'flex', gap: 12 }}>
<Tooltip.Root followCursorAxis="both">
<Tooltip.Root trackCursorAxis="both">
Copy link
Member Author

Choose a reason for hiding this comment

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

It's not clear to me why it started to fail now, but I guess it's a good thing it fails.

<AnchorButton>Anchor</AnchorButton>
<Tooltip.Positioner sideOffset={5}>
<TooltipPopup>Tooltip</TooltipPopup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { styled } from '@mui/system';
export default function UnstyledTooltipFollowCursor() {
return (
<div style={{ display: 'flex', gap: 12 }}>
<Tooltip.Root followCursorAxis="both">
<Tooltip.Root trackCursorAxis="both">
<AnchorButton>Anchor</AnchorButton>
<Tooltip.Positioner sideOffset={5}>
<TooltipPopup>Tooltip</TooltipPopup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Tooltip.Root followCursorAxis="both">
<Tooltip.Root trackCursorAxis="both">
<AnchorButton>Anchor</AnchorButton>
<Tooltip.Positioner sideOffset={5}>
<TooltipPopup>Tooltip</TooltipPopup>
Expand Down
2 changes: 1 addition & 1 deletion docs/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
1 change: 1 addition & 0 deletions docs/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const nextConfig = {
: {}),
experimental: {
esmExternals: true,
workerThreads: false,
},
};

Expand Down
12 changes: 6 additions & 6 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
"fast-glob": "^3.3.2",
"lodash": "^4.17.21",
"lz-string": "^1.5.0",
"next": "^14.2.13",
"next": "canary",
"postcss": "^8.4.47",
"postcss-import": "^16.1.0",
"prop-types": "^15.8.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react": "rc",
"react-dom": "rc",
"react-error-boundary": "^4.0.13",
"react-is": "^18.3.1",
"react-is": "rc",
"react-router-dom": "^6.23.1",
"react-runner": "^1.0.5",
"react-simple-code-editor": "^0.13.1",
Expand All @@ -70,8 +70,8 @@
"@types/hast": "^3.0.4",
"@types/node": "^18.19.54",
"@types/prop-types": "^15.7.13",
"@types/react": "^18.3.10",
"@types/react-dom": "^18.3.0",
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc",
"@types/unist": "^3.0.3",
"chai": "^4.5.0",
"framer-motion": "^11.9.0",
Expand Down
2 changes: 1 addition & 1 deletion docs/src/blocks/Demo/DemoSourceCopy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ export namespace DemoSourceCopy {
export interface Props extends React.ButtonHTMLAttributes<HTMLButtonElement> {
onCopied?: () => void;
onError?: (error: unknown) => void;
render?: React.ReactElement;
render?: React.ReactElement<React.ComponentPropsWithRef<'button'>>;
}
}
4 changes: 2 additions & 2 deletions docs/src/blocks/GoogleAnalytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ const GoogleAnalytics = React.memo(function GoogleAnalytics(props: GoogleAnalyti
}
}, []);

const timeout = React.useRef<NodeJS.Timeout>();
const timeout = React.useRef<ReturnType<typeof setTimeout> | null>(null);

React.useEffect(() => {
// Wait for the title to be updated.
// React fires useEffect twice in dev mode
clearTimeout(timeout.current);
clearTimeout(timeout.current ?? undefined);
timeout.current = setTimeout(() => {
// Remove hash as it's never sent to the server
// https://github.com/vercel/next.js/issues/25202
Expand Down
2 changes: 1 addition & 1 deletion docs/src/design-system/ToggleButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ export const ToggleButtonGroup = React.forwardRef(function ToggleButtonGroup<
);
}) as <Option extends { value: string; label: string }>(
props: ToggleButtonGroupProps<Option> & { ref?: React.Ref<HTMLDivElement> },
) => JSX.Element;
) => React.JSX.Element;
Copy link
Member

Choose a reason for hiding this comment

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

👍 to bring this to the main branch

Copy link
Member Author

Choose a reason for hiding this comment

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

I intend to have everything (except for package.json changes) merged to master.

2 changes: 1 addition & 1 deletion docs/src/design-system/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function Tooltip(props: Tooltip.Props) {
export namespace Tooltip {
export interface Props {
label: string;
children: React.ReactElement;
children: React.ReactElement<unknown>;
side?: 'top' | 'right' | 'bottom' | 'left';
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"@types/lodash": "^4.17.9",
"@types/mocha": "^10.0.8",
"@types/node": "^18.19.54",
"@types/react": "^18.3.10",
"@types/react": "npm:types-react@rc",
"@types/yargs": "^17.0.33",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
Expand Down Expand Up @@ -185,8 +185,8 @@
"@definitelytyped/typescript-versions": "^0.1.4",
"@definitelytyped/utils": "^0.1.7",
"@types/node": "^18.19.54",
"@types/react": "^18.3.10",
"@types/react-dom": "18.3.0"
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc"
},
"nyc": {
"include": [
Expand Down
16 changes: 8 additions & 8 deletions packages/mui-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,27 @@
},
"devDependencies": {
"@mui/internal-test-utils": "1.0.14",
"@testing-library/react": "^15.0.7",
"@testing-library/react": "latest",
"@testing-library/user-event": "^14.5.2",
"@types/chai": "^4.3.20",
"@types/chai-dom": "^1.11.3",
"@types/prop-types": "^15.7.13",
"@types/react": "^18.3.10",
"@types/react-dom": "^18.3.0",
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc",
"@types/sinon": "^17.0.3",
"@types/use-sync-external-store": "^0.0.6",
"chai": "^4.5.0",
"fast-glob": "^3.3.2",
"lodash": "^4.17.21",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react": "rc",
"react-dom": "rc",
"sinon": "^17.0.1",
"typescript": "^5.4.5"
},
"peerDependencies": {
"@types/react": "^17.0.0 || ^18.0.0",
"react": "^17.0.0 || ^18.0.0",
"react-dom": "^17.0.0 || ^18.0.0"
"@types/react": "^17 || ^18 || ^19",
"react": "^17 || ^18 || ^19",
"react-dom": "^17 || ^18 || ^19"
},
"peerDependenciesMeta": {
"@types/react": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('<AlertDialog.Backdrop />', () => {
refInstanceof: window.HTMLDivElement,
render: (node) => {
return render(
<AlertDialog.Root open modal={false} animated={false}>
<AlertDialog.Root open animated={false}>
{node}
</AlertDialog.Root>,
);
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-base/src/Checkbox/Root/useCheckboxRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useEnhancedEffect } from '../../utils/useEnhancedEffect';
import { useFieldRootContext } from '../../Field/Root/FieldRootContext';
import { useFieldControlValidation } from '../../Field/Control/useFieldControlValidation';
import { useField } from '../../Field/useField';
import { getInertValue } from '../../utils/getInertValue';

export function useCheckboxRoot(params: UseCheckboxRoot.Parameters): UseCheckboxRoot.ReturnValue {
const {
Expand Down Expand Up @@ -126,7 +127,7 @@ export function useCheckboxRoot(params: UseCheckboxRoot.Parameters): UseCheckbox
type: 'checkbox',
'aria-hidden': true,
// @ts-ignore
inert: 'true',
inert: getInertValue(true),
onChange(event) {
// Workaround for https://github.com/facebook/react/issues/9023
if (event.nativeEvent.defaultPrevented) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export function useCollapsibleContent(

const [height, setHeight] = React.useState(0);

const latestAnimationNameRef = React.useRef<string | undefined>('none');
const originalTransitionDurationStyleRef = React.useRef<string | undefined>();
const latestAnimationNameRef = React.useRef<string>('none');
const originalTransitionDurationStyleRef = React.useRef<string | null>(null);

const isTransitioningRef = React.useRef(false);

Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Dialog/Popup/useDialogPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function useDialogPopup(parameters: UseDialogPopupParameters): UseDialogP
onOpenChange,
});

const popupRef = React.useRef<HTMLElement | null>(null);
const popupRef = React.useRef<HTMLElement>(null);

const dismiss = useDismiss(context, {
outsidePressEvent: 'mousedown',
Expand Down
10 changes: 5 additions & 5 deletions packages/mui-base/src/Field/Validity/FieldValidity.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('<Field.Validity />', () => {
fireEvent.change(input, { target: { value: 'test' } });
fireEvent.blur(input);

const [data] = handleValidity.args[8];
const [data] = handleValidity.lastCall.args;
Copy link
Member Author

Choose a reason for hiding this comment

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

@atomiks, could you please verify that with these changes the intent of these checks is the same?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's fine


expect(data.value).to.equal('test');
expect(data.validity.valueMissing).to.equal(false);
Expand All @@ -44,8 +44,8 @@ describe('<Field.Validity />', () => {
fireEvent.focus(input);
fireEvent.blur(input);

expect(handleValidity.args[6][0].error).to.equal('error');
expect(handleValidity.args[6][0].errors).to.deep.equal(['error']);
expect(handleValidity.lastCall.args[0].error).to.equal('error');
expect(handleValidity.lastCall.args[0].errors).to.deep.equal(['error']);
});

it('should correctly pass errors when validate function returns an array of strings', () => {
Expand All @@ -63,7 +63,7 @@ describe('<Field.Validity />', () => {
fireEvent.focus(input);
fireEvent.blur(input);

expect(handleValidity.args[6][0].error).to.equal('1');
expect(handleValidity.args[6][0].errors).to.deep.equal(['1', '2']);
expect(handleValidity.lastCall.args[0].error).to.equal('1');
expect(handleValidity.lastCall.args[0].errors).to.deep.equal(['1', '2']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
import { mergeReactProps } from '../../utils/mergeReactProps';
import { useAnchorPositioning } from '../../utils/useAnchorPositioning';
import type { GenericHTMLProps } from '../../utils/types';
import { getInertValue } from '../../utils/getInertValue';

export function useMenuPositioner(
params: useMenuPositioner.Parameters,
Expand Down Expand Up @@ -43,7 +44,7 @@ export function useMenuPositioner(
zIndex: 2147483647, // max z-index
},
'aria-hidden': !open || undefined,
inert: !open ? '' : undefined,
inert: getInertValue(!open),
});
},
[positionerStyles, open, keepMounted, hidden],
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/NoSsr/NoSsr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { NoSsrProps } from './NoSsr.types';
*
* - [NoSsr API](https://base-ui.netlify.app/components/react-no-ssr/#api-reference-NoSsr)
*/
function NoSsr(props: NoSsrProps): JSX.Element {
function NoSsr(props: NoSsrProps): React.JSX.Element {
const { children, defer = false, fallback = null } = props;
const [mountedState, setMountedState] = React.useState(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ export namespace UseNumberFieldRoot {
isScrubbing: boolean;
inputRef: ((instance: HTMLInputElement | null) => void) | null;
scrubHandleRef: React.RefObject<ScrubHandle | null>;
scrubAreaRef: React.RefObject<HTMLSpanElement>;
scrubAreaCursorRef: React.RefObject<HTMLSpanElement>;
scrubAreaRef: React.RefObject<HTMLSpanElement | null>;
scrubAreaCursorRef: React.RefObject<HTMLSpanElement | null>;
}
}
2 changes: 1 addition & 1 deletion packages/mui-base/src/NumberField/Root/useScrub.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface ScrubParams {
disabled: boolean;
readOnly: boolean;
value: number | null;
inputRef: React.RefObject<HTMLInputElement>;
inputRef: React.RefObject<HTMLInputElement | null>;
incrementValue: (amount: number, dir: 1 | -1, currentValue?: number | null) => void;
getStepAmount: () => number | undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
import { mergeReactProps } from '../../utils/mergeReactProps';
import { useAnchorPositioning } from '../../utils/useAnchorPositioning';
import type { GenericHTMLProps } from '../../utils/types';
import { getInertValue } from '../../utils/getInertValue';

export function usePopoverPositioner(
params: usePopoverPositioner.Parameters,
Expand Down Expand Up @@ -38,7 +39,7 @@ export function usePopoverPositioner(
return mergeReactProps<'div'>(externalProps, {
role: 'presentation',
// @ts-ignore
inert: open ? undefined : 'true',
inert: getInertValue(open),
style: {
...positionerStyles,
...hiddenStyles,
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Popover/Root/PopoverRootContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface PopoverRootContext {
setTriggerElement: (el: Element | null) => void;
positionerElement: HTMLElement | null;
setPositionerElement: (el: HTMLElement | null) => void;
popupRef: React.RefObject<HTMLElement>;
popupRef: React.RefObject<HTMLElement | null>;
delay: number;
closeDelay: number;
delayType: 'rest' | 'hover';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Popover/Root/usePopoverRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,6 @@ export namespace usePopoverRoot {
setTriggerElement: React.Dispatch<React.SetStateAction<Element | null>>;
positionerElement: HTMLElement | null;
setPositionerElement: React.Dispatch<React.SetStateAction<HTMLElement | null>>;
popupRef: React.RefObject<HTMLElement>;
popupRef: React.RefObject<HTMLElement | null>;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface PreviewCardRootContext {
getRootPopupProps: (externalProps?: GenericHTMLProps) => GenericHTMLProps;
floatingRootContext: FloatingRootContext;
transitionStatus: TransitionStatus;
popupRef: React.RefObject<HTMLElement>;
popupRef: React.RefObject<HTMLElement | null>;
}

export const PreviewCardRootContext = React.createContext<PreviewCardRootContext | null>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,6 @@ export namespace usePreviewCardRoot {
setTriggerElement: React.Dispatch<React.SetStateAction<Element | null>>;
positionerElement: HTMLElement | null;
setPositionerElement: React.Dispatch<React.SetStateAction<HTMLElement | null>>;
popupRef: React.RefObject<HTMLDivElement>;
popupRef: React.RefObject<HTMLDivElement | null>;
}
}
4 changes: 2 additions & 2 deletions packages/mui-base/src/Slider/Control/useSliderControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function useSliderControl(
const handleRootRef = useForkRef(externalRef, registerSliderControl, controlRef);

// A number that uniquely identifies the current finger in the touch session.
const touchIdRef = React.useRef<number>();
const touchIdRef = React.useRef<number | null>(null);

const moveCountRef = React.useRef(0);

Expand Down Expand Up @@ -123,7 +123,7 @@ export function useSliderControl(
onValueCommitted(newFingerValue.newValue, nativeEvent);
}

touchIdRef.current = undefined;
touchIdRef.current = null;

// eslint-disable-next-line @typescript-eslint/no-use-before-define
stopListening();
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-base/src/Slider/Root/SliderRoot.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type { FieldRootOwnerState } from '../../Field/Root/FieldRoot.types';

export interface SliderThumbMetadata {
inputId: string;
ref: React.RefObject<HTMLElement>;
inputRef: React.RefObject<HTMLInputElement>;
ref: React.RefObject<HTMLElement | null>;
inputRef: React.RefObject<HTMLInputElement | null>;
}

export type SliderContextValue = Omit<
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Slider/Root/useSliderRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function useSliderRoot(parameters: UseSliderParameters): UseSliderReturnValue {

const isRtl = direction === 'rtl';

const previousIndexRef = React.useRef<number>();
const previousIndexRef = React.useRef<number | null>(null);
let axis = orientation;
if (isRtl && orientation === 'horizontal') {
axis += '-reverse';
Expand Down
Loading