callstack / callstack/react-native-paper
Card component injects invalid props into React.Fragment children
- Dominant language
- TypeScript
- Stars
- 14.5k
- Forks
- 2.2k
- Avg merge
- 5d 23h
- Merged PRs (30d)
- 12
Description
### Current behaviour
The Card component clones its children and injects additional props (index, total, siblings, borderRadiusStyles). This leads to runtime errors when a child is a React.Fragment, which only accepts key and children props. Other components that do not expect these props may also be affected.

### Expected behaviour
The Card component should render React.Fragment children without throwing runtime errors by avoiding invalid prop injection.
### How to reproduce?
Pass a React.Fragment as a child of Card.
### What have you tried so far?
Relevant source line: https://github.com/callstack/react-native-paper/blob/main/src/components/Card/Card.tsx#L278
Potential fix:
```tsx
import { Fragment } from 'react';
// ...
const content = (
{React.Children.map(children, (child, index) => {
if (!React.isValidElement(child)) {
return child;
}
if (child.type === Fragment) {
return child;
}
return React.cloneElement(child as React.ReactElement, {
index,
total,
siblings,
borderRadiusStyles,
});
})}
);
```
Contributor guide
Research direction
Start at the child-handling code near line 278 of src/components/Card/Card.tsx and reproduce the issue by passing a React.Fragment to Card. Check how cloned children receive props and verify that Fragment children render without a runtime error or invalid prop injection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react-native, typescript
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100