mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 18:26:05 +08:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added new admin routes: "auth", "setup", and "notFound" for improved navigation and access within the admin interface. - Introduced a utility for simplified and flexible lazy loading of React components with fallback support. - **Improvements** - Updated routing structure in the admin frontend for clearer route management and enhanced Sentry integration. - Centralized route definitions for easier maintenance and consistency. - Upgraded dependencies to support the latest React Router and React versions. - Enhanced asynchronous handling in setup form navigation. - **Chores** - Updated project references and workspace dependencies for better package management. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
38 lines
842 B
TypeScript
38 lines
842 B
TypeScript
import React, {
|
|
type ComponentProps,
|
|
type ComponentType,
|
|
lazy as reactLazy,
|
|
Suspense,
|
|
} from 'react';
|
|
|
|
export function lazy<T extends ComponentType<any>>(
|
|
factory: () => Promise<Record<any, T>>,
|
|
fallback?: React.ReactNode
|
|
) {
|
|
const LazyComponent = reactLazy(() =>
|
|
factory().then(mod => {
|
|
if ('default' in mod) {
|
|
return { default: mod.default };
|
|
} else {
|
|
const components = Object.values(mod);
|
|
if (components.length > 1) {
|
|
console.warn('Lazy loaded module has more then one exports');
|
|
}
|
|
return {
|
|
default: components[0],
|
|
};
|
|
}
|
|
})
|
|
);
|
|
|
|
return function LazyRoute(props: ComponentProps<T>) {
|
|
return React.createElement(
|
|
Suspense,
|
|
{
|
|
fallback,
|
|
},
|
|
React.createElement(LazyComponent, props)
|
|
);
|
|
};
|
|
}
|