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

remove full page loader from global app level boundary suspense #2028

Merged
merged 2 commits into from
Oct 18, 2023
Merged
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
33 changes: 27 additions & 6 deletions apps/web/src/contexts/boundary/Boundary.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
import { memo, PropsWithChildren, Suspense } from 'react';
import { useRouter } from 'next/router';
import { memo, PropsWithChildren, Suspense, useMemo } from 'react';

import FullPageLoader from '~/components/core/Loader/FullPageLoader';

import ErrorBoundary from './ErrorBoundary';

const Boundary = memo(({ children }: PropsWithChildren) => (
<Suspense fallback={<FullPageLoader />}>
<ErrorBoundary>{children}</ErrorBoundary>
</Suspense>
));
const NO_FULL_PAGE_LOADER_PATHS = ['/features'];

const isPathExcluded = (pathname: string) => {
return NO_FULL_PAGE_LOADER_PATHS.some((path) => pathname.startsWith(path));
};

const Boundary = memo(({ children }: PropsWithChildren) => {
const { pathname } = useRouter();

const isFullPageLoaderExcluded = useMemo(() => isPathExcluded(pathname), [pathname]);

if (isFullPageLoaderExcluded) {
return (
<Suspense>
<ErrorBoundary>{children}</ErrorBoundary>;
</Suspense>
);
}

return (
<Suspense fallback={<FullPageLoader />}>
<ErrorBoundary>{children}</ErrorBoundary>
</Suspense>
);
});

Boundary.displayName = 'Boundary';

Expand Down