Skip to content

Commit f711f7e

Browse files
authored
Merge pull request #8659 from marmelab/fix-ArrayField-when-value-is-null
Fix ArrayField breaking when value is null
2 parents 9cc2705 + a41a751 commit f711f7e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/ra-ui-materialui/src/field/ArrayField.spec.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ describe('<ArrayField />', () => {
4343
);
4444
});
4545

46+
it('should not fail when value is null', () => {
47+
render(
48+
<Wrapper>
49+
<ArrayField source="arr" record={{ id: 123, arr: null }}>
50+
<DummyIterator />
51+
</ArrayField>
52+
</Wrapper>
53+
);
54+
});
55+
4656
it('should render the alternative empty component', () => {
4757
const { queryByText } = render(
4858
<Wrapper>

packages/ra-ui-materialui/src/field/ArrayField.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import { PublicFieldProps, InjectedFieldProps, fieldPropTypes } from './types';
7575
export const ArrayField: FC<ArrayFieldProps> = memo(props => {
7676
const { children, resource, source } = props;
7777
const record = useRecordContext(props);
78-
const data = get(record, source, emptyArray);
78+
const data = get(record, source, emptyArray) || emptyArray;
7979

8080
return (
8181
<ListContextProvider

0 commit comments

Comments
 (0)