route-level-code-split icon indicating copy to clipboard operation
route-level-code-split copied to clipboard

Fallback for nested lazy loading?

Open tal-rofe opened this issue 2 years ago • 2 comments

The usage in this repository is good for root level routes only. If there are some nested routes (which are also lazy loaded..), then the fallback value for React.Suspense will be only the nested lazy loaded "page", and that will make a bad UI for the fallback.

Assume you have a lazy loaded component X with some navbar element. Then, you configure in this component X an <Outlet />. Then, if the future-injected <Outlet> element will be lazy loaded as well, the root <React.Suspense> will be loaded with partial fallback element, as the fallback element will be the content of the <Outlet>, but the real "page" includes also the navbar, which won't be shown in the fallback state.

Is there a way to overcome it?

tal-rofe avatar Feb 24 '23 12:02 tal-rofe

The usage in this repository is good for root level routes only. If there are some nested routes (which are also lazy loaded..), then the fallback value for React.Suspense will be only the nested lazy loaded "page", and that will make a bad UI for the fallback.

Assume you have a lazy loaded component X with some navbar element. Then, you configure in this component X an <Outlet />. Then, if the future-injected <Outlet> element will be lazy loaded as well, the root <React.Suspense> will be loaded with partial fallback element, as the fallback element will be the content of the <Outlet>, but the real "page" includes also the navbar, which won't be shown in the fallback state.

Is there a way to overcome i

Hi tal-rofe, Have you solved this problem yet?

trandinhhiep789 avatar Nov 30 '23 07:11 trandinhhiep789

@trandinhhiep789 Yes I have an open source project where I solved it. You can see it in Exlint/dashboard repository in my profile: https://github.com/Exlint/dashboard/blob/main/apps/frontend/src/App.router.tsx

tal-rofe avatar Nov 30 '23 07:11 tal-rofe