Skip to content

Commit

Permalink
Merge pull request #8659 from marmelab/fix-ArrayField-when-value-is-null
Browse files Browse the repository at this point in the history
Fix ArrayField breaking when value is null
  • Loading branch information
fzaninotto authored Feb 15, 2023
2 parents 9cc2705 + a41a751 commit f711f7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/ra-ui-materialui/src/field/ArrayField.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ describe('<ArrayField />', () => {
);
});

it('should not fail when value is null', () => {
render(
<Wrapper>
<ArrayField source="arr" record={{ id: 123, arr: null }}>
<DummyIterator />
</ArrayField>
</Wrapper>
);
});

it('should render the alternative empty component', () => {
const { queryByText } = render(
<Wrapper>
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/field/ArrayField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import { PublicFieldProps, InjectedFieldProps, fieldPropTypes } from './types';
export const ArrayField: FC<ArrayFieldProps> = memo(props => {
const { children, resource, source } = props;
const record = useRecordContext(props);
const data = get(record, source, emptyArray);
const data = get(record, source, emptyArray) || emptyArray;

return (
<ListContextProvider
Expand Down

0 comments on commit f711f7e

Please sign in to comment.