diff --git a/packages/ra-core/src/core/useConfigureAdminRouterFromChildren.spec.tsx b/packages/ra-core/src/core/useConfigureAdminRouterFromChildren.spec.tsx
index 873dbb8738a..1a0a1dfa213 100644
--- a/packages/ra-core/src/core/useConfigureAdminRouterFromChildren.spec.tsx
+++ b/packages/ra-core/src/core/useConfigureAdminRouterFromChildren.spec.tsx
@@ -56,6 +56,30 @@ const TestedComponent = ({ role }) => {
);
};
+const TestedComponentReturningNull = ({ role }) => {
+ const history = createMemoryHistory();
+
+ return (
+
+
+
+
+ {() =>
+ role === 'admin'
+ ? [, ]
+ : role === 'user'
+ ? []
+ : null
+ }
+
+
+ );
+};
+
const ResourceWithPermissions = (props: ResourceProps) => (
);
@@ -168,6 +192,12 @@ describe('useConfigureAdminRouterFromChildren', () => {
expectResource('user').not.toBeNull();
expectResource('admin').not.toBeNull();
});
+ it('should accept function returning null', async () => {
+ render();
+ await waitFor(() => expect(screen.queryByText('Loading')).toBeNull());
+ expectResource('user').not.toBeNull();
+ expectResource('admin').not.toBeNull();
+ });
it('should call registerResource with the permissions', async () => {
render();
await waitFor(() => expect(screen.queryByText('Loading')).toBeNull());
diff --git a/packages/ra-core/src/core/useConfigureAdminRouterFromChildren.tsx b/packages/ra-core/src/core/useConfigureAdminRouterFromChildren.tsx
index 707167da7a7..8147c20598a 100644
--- a/packages/ra-core/src/core/useConfigureAdminRouterFromChildren.tsx
+++ b/packages/ra-core/src/core/useConfigureAdminRouterFromChildren.tsx
@@ -97,7 +97,7 @@ const useRoutesAndResourcesFromChildren = (
) => {
try {
const childrenFuncResult = childFunc(permissions);
- if ((childrenFuncResult as Promise).then) {
+ if ((childrenFuncResult as Promise)?.then) {
(childrenFuncResult as Promise).then(
resolvedChildren => {
mergeRoutesAndResources(