adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.58k stars 1.09k forks source link

[RAC] Breaking change to `children` type in `BreadcrumbProps` in v1.3.2 #6956

Closed andrew-pledge-io closed 2 weeks ago

andrew-pledge-io commented 2 weeks ago

Provide a general summary of the issue here

There was a breaking change in the RAC <Breadcrumb> component where the type of children in BreadcrumbProps changed from ReactNode to ReactNode | (props: RenderProps) => ReactNode.

see: https://github.com/adobe/react-spectrum/commit/660e768998b253af8233419437fab863d2b8c2cd#diff-3665b56a6e79754081f2590fccd7fbfb79570f1101922c5e71fea9e2360fccb5L71

This started causing type errors where BreadcrumbProps['children'] was being rendered in JSX as it's no longer a JSX compatible type.

There were no release notes for v1.3.2 or v1.3.3 so it was a bit tricky to track down, I'm creating this issue to document the change for others rather than expecting any kind of fix to be released.

😯 Current Behavior

import type { BreadcrumbProps } from 'react-aria-components';
import { Breadcrumb } from 'react-aria-components';

export function MyBreadcrumb(props: BreadcrumbProps) {
  return (
    <Breadcrumb {...props}>
      <div className="my-style-wrapper">
        {/* ok in react-aria-components 1.3.1, type error in 1.3.2 */}
        {props.children}
      </div>
    </Breadcrumb>
  );
}

💁 Possible Solution

Users of Breadcrumb can fix their code by using composeRenderProps:

import type { BreadcrumbProps } from 'react-aria-components';
import { Breadcrumb, composeRenderProps } from 'react-aria-components';

export function MyBreadcrumb(props: BreadcrumbProps) {
  return (
    <Breadcrumb {...props}>
      {composeRenderProps(props.children, (children) => (
        <div className="my-style-wrapper">{children}</div>
      ))}
    </Breadcrumb>
  );
}

🔦 Context

Our environment uses Renovate to automatically pick up new package versions.

When it picked up react-aria-components@1.3.2, the PR pipelines started failing due to this change in types.

🖥️ Steps to Reproduce

  1. Install react-aria-components@1.3.1
  2. Create a component that renders BreadcrumbProps['children'] as JSX
  3. Update to react-aria-components@1.3.2
  4. Run TypeScript type checker

Version

v1.3.2

What browsers are you seeing the problem on?

Other

If other, please specify.

No response

What operating system are you using?

MacOS

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

devongovett commented 2 weeks ago

Sorry about that. This was a bug in the types. Children can be a function due to render props but the types were not reflecting reality.