Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix home page crashing when using react-router lazy import #5801

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/apps/experimental/routes/asyncRoutes/user.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import loadable from '@loadable/component';
import { AsyncRoute, AsyncRouteType } from '../../../../components/router/AsyncRoute';

export const ASYNC_USER_ROUTES: AsyncRoute[] = [
{
path: 'home.html',
// FIXME: The use of tab manager for the home screen breaks when using lazy route handling
Component: loadable(() => import('../home'))
},
{ path: 'quickconnect', page: 'quickConnect' },
{ path: 'search.html', page: 'search' },
{ path: 'userprofile.html', page: 'user/userprofile' },
{ path: 'home.html', page: 'home', type: AsyncRouteType.Experimental },
{ path: 'movies.html', page: 'movies', type: AsyncRouteType.Experimental },
{ path: 'tv.html', page: 'shows', type: AsyncRouteType.Experimental },
{ path: 'music.html', page: 'music', type: AsyncRouteType.Experimental },
Expand Down
27 changes: 20 additions & 7 deletions src/components/router/AsyncRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface AsyncRoute {
page?: string
/** The page type used to load the correct page element. */
type?: AsyncRouteType
/** Override for pages that don't support lazy importing */
Component?: React.ComponentType | null;
}

const importPage = (page: string, type: AsyncRouteType) => {
Expand All @@ -29,12 +31,23 @@ const importPage = (page: string, type: AsyncRouteType) => {
}
};

export const toAsyncPageRoute = ({ path, page, type = AsyncRouteType.Stable }: AsyncRoute): RouteObject => ({
export const toAsyncPageRoute = ({
path,
lazy: async () => {
const { default: Component } = await importPage(page ?? path, type);
return {
Component
};
page,
Component,
type = AsyncRouteType.Stable
}: AsyncRoute): RouteObject => {
if (Component) {
return { path, Component };
}
});

return {
path,
lazy: async () => {
const { default: Page } = await importPage(page ?? path, type);
return {
Component: Page
};
}
};
};
Loading