Skip to content

feat: polish types to be compatible with React 18.3 #4735

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"license": "MIT",
"resolutions": {
"@types/eslint": "^8.37.0",
"@types/react": ">=18.3.1",
"@types/react-dom": ">=18.3.1",
"@types/react": "^18.3.0",
"@types/react-dom": "^18.3.0",
"ts-node": "^10.9.2"
},
"devDependencies": {
Expand Down Expand Up @@ -113,8 +113,8 @@
"prettier": "^2.8.7",
"prettier-plugin-tailwindcss": "^0.4.1",
"raf": "^3.4.1",
"react": ">=18.3.1",
"react-dom": ">=18.3.1",
"react": "^18.3.0",
"react-dom": "^18.3.0",
"remark-cli": "^12.0.1",
"remark-frontmatter": "^2.0.0",
"remark-lint": "^8.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/orbit-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
},
"peerDependencies": {
"@babel/runtime": "^7.21.0",
"react": ">=18.3.1",
"react-dom": ">=18.3.1"
"react": "^18.3.0",
"react-dom": "^18.3.0"
},
"dependencies": {
"@floating-ui/react": "0.26.24",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const AccordionSection = ({
)}

<Slide maxHeight={height} expanded={isExpanded} id={slideId}>
<div ref={ref}>
<div ref={ref as React.RefObject<HTMLDivElement>}>
{children && <SectionContent dataTest={dataTest}>{children}</SectionContent>}
{footer && <SectionFooter dataTest={dataTest}>{footer}</SectionFooter>}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function Expandable({ expanded, children, slideID }: Props) {

return (
<Slide maxHeight={height} expanded={expanded} id={slideID}>
<div ref={ref}>{children}</div>
<div ref={ref as React.RefObject<HTMLDivElement>}>{children}</div>
</Slide>
);
}
2 changes: 1 addition & 1 deletion packages/orbit-components/src/Collapse/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const Collapse = ({
</Stack>
</div>
<Slide maxHeight={height} expanded={expanded} id={slideID}>
<div className="my-300 mx-0" ref={node}>
<div className="my-300 mx-0" ref={node as React.RefObject<HTMLDivElement>}>
{children}
</div>
</Slide>
Expand Down
6 changes: 3 additions & 3 deletions packages/orbit-components/src/InputSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ const InputSelect = React.forwardRef<HTMLInputElement, Props>(
id={optionId}
active={activeIdx === idx}
isSelected={isSelected}
ref={optionRef}
ref={optionRef as React.RefObject<HTMLDivElement>}
title={title}
description={description}
prefix={prefix}
Expand Down Expand Up @@ -325,7 +325,7 @@ const InputSelect = React.forwardRef<HTMLInputElement, Props>(
id={optionId}
active={!!isLargeMobile && activeIdx === optionIdx}
isSelected={isSelected}
ref={optionRef}
ref={optionRef as React.RefObject<HTMLDivElement>}
title={title}
description={description}
prefix={prefix}
Expand Down Expand Up @@ -367,7 +367,7 @@ const InputSelect = React.forwardRef<HTMLInputElement, Props>(
id={optionId}
active={activeIdx === optionIdx}
isSelected={isSelected}
ref={optionRef}
ref={optionRef as React.RefObject<HTMLDivElement>}
title={title}
description={description}
prefix={prefix}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ const ItinerarySegmentDetail = ({
ariaLabelledBy={randomId("slide")}
stopClickPropagation={false}
>
<div className="pt-300 cursor-pointer overflow-hidden" ref={slideRef}>
<div
className="pt-300 cursor-pointer overflow-hidden"
ref={slideRef as React.RefObject<HTMLDivElement>}
>
<div
className="px-300 z-default relative py-0"
style={{
Expand Down
1 change: 1 addition & 0 deletions packages/orbit-components/src/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const Modal = React.forwardRef<Instance, Props>(
if (typeof scrollingElementRef === "function") {
scrollingElementRef(node);
} else {
// @ts-expect-error TODO
// eslint-disable-next-line no-param-reassign
scrollingElementRef.current = node;
Comment on lines +95 to 97
Copy link

Choose a reason for hiding this comment

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

🐛 Possible Bug
The // @ts-expect-error suppresses a type error without proper type checking. If scrollingElementRef is not a valid React ref object with a current property, this assignment could cause runtime errors. Consider adding proper type guards or using MutableRefObject type.

Suggested change
// @ts-expect-error TODO
// eslint-disable-next-line no-param-reassign
scrollingElementRef.current = node;
if (scrollingElementRef && 'current' in scrollingElementRef) {
scrollingElementRef.current = node;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ const TileExpandable = ({
/>
)}
<Slide maxHeight={height} expanded={isExpanded} id={slideID} ariaLabelledBy={labelID}>
<TileContent noPadding={noPadding} ref={node} withBorder={hasHeader}>
<TileContent
noPadding={noPadding}
ref={node as React.RefObject<HTMLDivElement>}
withBorder={hasHeader}
>
{children}
</TileContent>
</Slide>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import useBoundingRect from "..";

export default function Test() {
const [, ref] = useBoundingRect<HTMLDivElement>({ height: null });
return <div ref={ref} />;
return <div ref={ref as React.RefObject<HTMLDivElement>} />;
}
4 changes: 2 additions & 2 deletions packages/orbit-components/src/hooks/useBoundingRect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface Dimensions {

const useBoundingRect = <T extends HTMLElement>(
initialValue: Partial<Dimensions> | undefined | null,
): [Dimensions, React.RefObject<T | null>] => {
): [Dimensions, React.RefObject<T>] => {
const [state, setState] = React.useState<Dimensions>(() => ({
x: 0,
y: 0,
Expand All @@ -28,7 +28,7 @@ const useBoundingRect = <T extends HTMLElement>(
...initialValue,
}));

const ref = React.useRef<T | null>(null);
const ref = React.useRef<T>(null) as React.RefObject<T>;

React.useEffect(() => {
const calculate = () => {
Expand Down
1 change: 1 addition & 0 deletions packages/orbit-components/src/utils/mergeRefs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function mergeRefs<T = HTMLElement>(
if (typeof ref === "function") {
ref(value);
} else if (ref != null && typeof ref !== "string") {
// @ts-expect-error TODO
// eslint-disable-next-line no-param-reassign
ref.current = value;
}
Expand Down
50 changes: 28 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6671,6 +6671,11 @@
resolved "https://registry.npmjs.org/@types/prismjs/-/prismjs-1.26.0.tgz"
integrity sha512-ZTaqn/qSqUuAq1YwvOFQfVW1AR/oQJlLSZVustdjwI+GZ8kr0MSHBj0tsXPW1EqHubx50gtBEjbPGsdZwQwCjQ==

"@types/prop-types@*":
version "15.7.14"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.14.tgz#1433419d73b2a7ebfc6918dcefd2ec0d5cd698f2"
integrity sha512-gNMvNH49DJ7OJYv+KAKn0Xp45p8PLl6zo2YnvDIbTd4J6MER2BmWN49TG7n9LvkyihINxeKW8+3bfS2yDC9dzQ==

"@types/ps-tree@^1.1.2":
version "1.1.2"
resolved "https://registry.npmjs.org/@types/ps-tree/-/ps-tree-1.1.2.tgz"
Expand All @@ -6693,10 +6698,10 @@
dependencies:
"@types/react" "*"

"@types/react-dom@>=18.3.1", "@types/react-dom@^18.0.0", "@types/react-dom@^18.0.0 || ^19.0.0":
version "19.1.2"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-19.1.2.tgz#bd1fe3b8c28a3a2e942f85314dcfb71f531a242f"
integrity sha512-XGJkWF41Qq305SKWEILa1O8vzhb3aOo3ogBlSmiqNko/WmRb6QIaweuZCXjKygVDXpzXb5wyxKTSOsmkuqj+Qw==
"@types/react-dom@^18.0.0", "@types/react-dom@^18.0.0 || ^19.0.0", "@types/react-dom@^18.3.0":
version "18.3.7"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.3.7.tgz#b89ddf2cd83b4feafcc4e2ea41afdfb95a0d194f"
integrity sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==

"@types/react-helmet@^6.1.1":
version "6.1.6"
Expand All @@ -6712,11 +6717,12 @@
dependencies:
"@types/react" "*"

"@types/react@*", "@types/react@>=17.0.26", "@types/react@>=18.3.1", "@types/react@^18.0.0", "@types/react@^18.0.0 || ^19.0.0":
version "19.1.2"
resolved "https://registry.yarnpkg.com/@types/react/-/react-19.1.2.tgz#11df86f66f188f212c90ecb537327ec68bfd593f"
integrity sha512-oxLPMytKchWGbnQM9O7D67uPa9paTNxO7jVoNMXgkkErULBPhPARCfkKL9ytcIJJRGjbsVwW4ugJzyFFvm/Tiw==
"@types/react@*", "@types/react@>=17.0.26", "@types/react@^18.0.0", "@types/react@^18.0.0 || ^19.0.0", "@types/react@^18.3.0":
version "18.3.20"
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.3.20.tgz#b0dccda9d2f1bc24d2a04b1d0cb5d0b9a3576ad3"
integrity sha512-IPaCZN7PShZK/3t6Q87pfTkRm6oLTd4vztyoj+cbHUF1g3FfVb2tFIL79uCRKEfv16AhqDMBywP2VW3KIZUvcg==
dependencies:
"@types/prop-types" "*"
csstype "^3.0.2"

"@types/readable-stream@^2.3.13":
Expand Down Expand Up @@ -22887,21 +22893,21 @@ react-docgen@^7.0.0:
resolve "^1.22.1"
strip-indent "^4.0.0"

react-dom@>=18.3.1, react-dom@^19.0.0:
version "19.1.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-19.1.0.tgz#133558deca37fa1d682708df8904b25186793623"
integrity sha512-Xs1hdnE+DyKgeHJeJznQmYMIBG3TKIHJJT95Q58nHLSrElKlGQqDTR2HQ9fx5CN/Gk6Vh/kupBTDLU11/nDk/g==
dependencies:
scheduler "^0.26.0"

"react-dom@^16.8.0 || ^17.0.0 || ^18.0.0", react-dom@^18.0.0:
"react-dom@^16.8.0 || ^17.0.0 || ^18.0.0", react-dom@^18.0.0, react-dom@^18.3.0:
version "18.3.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.3.1.tgz#c2265d79511b57d479b3dd3fdfa51536494c5cb4"
integrity sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==
dependencies:
loose-envify "^1.1.0"
scheduler "^0.23.2"

react-dom@^19.0.0:
version "19.1.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-19.1.0.tgz#133558deca37fa1d682708df8904b25186793623"
integrity sha512-Xs1hdnE+DyKgeHJeJznQmYMIBG3TKIHJJT95Q58nHLSrElKlGQqDTR2HQ9fx5CN/Gk6Vh/kupBTDLU11/nDk/g==
dependencies:
scheduler "^0.26.0"

react-element-to-jsx-string@^14.3.2:
version "14.3.4"
resolved "https://registry.npmjs.org/react-element-to-jsx-string/-/react-element-to-jsx-string-14.3.4.tgz"
Expand Down Expand Up @@ -23065,18 +23071,18 @@ react-window@^1.8.10:
"@babel/runtime" "^7.0.0"
memoize-one ">=3.1.1 <6"

react@>=18.3.1, react@^19.0.0:
version "19.1.0"
resolved "https://registry.yarnpkg.com/react/-/react-19.1.0.tgz#926864b6c48da7627f004795d6cce50e90793b75"
integrity sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg==

"react@^16.8.0 || ^17.0.0 || ^18.0.0", react@^18.0.0:
"react@^16.8.0 || ^17.0.0 || ^18.0.0", react@^18.0.0, react@^18.3.0:
version "18.3.1"
resolved "https://registry.yarnpkg.com/react/-/react-18.3.1.tgz#49ab892009c53933625bd16b2533fc754cab2891"
integrity sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==
dependencies:
loose-envify "^1.1.0"

react@^19.0.0:
version "19.1.0"
resolved "https://registry.yarnpkg.com/react/-/react-19.1.0.tgz#926864b6c48da7627f004795d6cce50e90793b75"
integrity sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg==

reactcss@^1.2.0:
version "1.2.3"
resolved "https://registry.npmjs.org/reactcss/-/reactcss-1.2.3.tgz"
Expand Down