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

chore: Use lazyRetry in dynamic imports #163

Merged
merged 2 commits into from
Dec 7, 2023
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
4 changes: 3 additions & 1 deletion packages/frontend/src/api/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ const REFRESH_KEY = "retry-lazy-refresh-key";
*
* @param componentImport an import function that returns a promise
*/
export const lazyRetry = <T extends React.FC>(

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const lazyRetry = <T extends React.FC<any>>(
componentImport: () => Promise<{ default: T }>
): React.LazyExoticComponent<T> => {
return lazy<T>(
Expand Down
8 changes: 4 additions & 4 deletions packages/frontend/src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { lazy } from "react";
import { lazyRetry } from "./api/utils/helpers";
import PreloaderPage from "./pages/preloader";

const PreloaderPage = lazy(() => import("./pages/preloader"));
const DashboardPage = lazy(() => import("./pages/index"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no point in lazy loading this one because it's used elsewhere in a suspense, which cannot take a lazy loaded component.

const ErrorPage = lazy(() => import("./pages/error"));
const DashboardPage = lazyRetry(() => import("./pages/index"));
const ErrorPage = lazyRetry(() => import("./pages/error"));

/**
* A basic route.
Expand Down
81 changes: 50 additions & 31 deletions packages/frontend/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { lazy } from "react";
import React from "react";
import {
TUserViewWidget,
TDynamicItem,
TSourceData,
TCounterData,
} from "src/api/types";
import { TAgendaItem } from "src/api/types/agenda";
import { lazyRetry } from "./api/utils/helpers";
import { ETemplateNameRegistry } from "./constants";

/**
Expand Down Expand Up @@ -56,60 +57,78 @@ export type TTemplatesDict = {
};

export const TEMPLATES_DICT: Partial<TTemplatesDict> = {
alphagpt_template: lazy(() => import("./containers/qna/QnAContainer")),
blog_template: lazy(() => import("./containers/items/ItemsContainer")),
custom_table_template: lazy(
alphagpt_template: lazyRetry(() => import("./containers/qna/QnAContainer")),
blog_template: lazyRetry(() => import("./containers/items/ItemsContainer")),
custom_table_template: lazyRetry(
() => import("./containers/custom-modules/CustomTableContainer")
),
dao_template: lazy(() => import("./containers/items/ItemsContainer")),
discord_template: lazy(() => import("./containers/items/ItemsContainer")),
faq_template: lazy(() => import("./containers/dynamic/FaqContainer")),
forum_template: lazy(() => import("./containers/items/ItemsContainer")),
gas_template: lazy(() => import("./containers/gas/GasContainer")),
latest_video_template: lazy(
dao_template: lazyRetry(() => import("./containers/items/ItemsContainer")),
discord_template: lazyRetry(
() => import("./containers/items/ItemsContainer")
),
faq_template: lazyRetry(() => import("./containers/dynamic/FaqContainer")),
forum_template: lazyRetry(
() => import("./containers/items/ItemsContainer")
),
gas_template: lazyRetry(() => import("./containers/gas/GasContainer")),
latest_video_template: lazyRetry(
() => import("./containers/media/MediaContainer")
),
lens_template: lazy(
lens_template: lazyRetry(
() => import("./containers/lens-feed/LensFeedContainer")
),
map_template: lazy(() => import("./containers/maps/MapContainer")),
market_template: lazy(() => import("./containers/market/MarketContainer")),
media_template: lazy(() => import("./containers/media/MediaContainer")),
news_template: lazy(() => import("./containers/items/ItemsContainer")),
podcast_template: lazy(
map_template: lazyRetry(() => import("./containers/maps/MapContainer")),
market_template: lazyRetry(
() => import("./containers/market/MarketContainer")
),
media_template: lazyRetry(
() => import("./containers/media/MediaContainer")
),
news_template: lazyRetry(() => import("./containers/items/ItemsContainer")),
podcast_template: lazyRetry(
() => import("./containers/podcast/PodcastContainer")
),
portfolio_template: lazy(
portfolio_template: lazyRetry(
() => import("./containers/portfolio/PortfolioContainer")
),
reddit_template: lazy(() => import("./containers/items/ItemsContainer")),
reports_template: lazy(
reddit_template: lazyRetry(
() => import("./containers/items/ItemsContainer")
),
reports_template: lazyRetry(
() => import("./containers/dynamic/ReportsContainer")
),
roadmap_template: lazy(
roadmap_template: lazyRetry(
() => import("./containers/dynamic/RoadmapContainer")
),
summary_template: lazy(
summary_template: lazyRetry(
() => import("./containers/summary/SummaryContainer")
),
talks_template: lazy(() => import("./containers/dynamic/AgendaContainer")),
tvl_template: lazy(() => import("./containers/tvl/TvlContainer")),
uniswap_template: lazy(() => import("./containers/uniswap/SwapContainer")),
venue_template: lazy(() => import("./containers/maps/VenueMapContainer")),
video_template: lazy(() => import("./containers/video/VideoContainer")),
calendar_template: lazy(
talks_template: lazyRetry(
() => import("./containers/dynamic/AgendaContainer")
),
tvl_template: lazyRetry(() => import("./containers/tvl/TvlContainer")),
uniswap_template: lazyRetry(
() => import("./containers/uniswap/SwapContainer")
),
venue_template: lazyRetry(
() => import("./containers/maps/VenueMapContainer")
),
video_template: lazyRetry(
() => import("./containers/video/VideoContainer")
),
calendar_template: lazyRetry(
() => import("./containers/calendar/CalendarContainer")
),
countdown_template: lazy(
countdown_template: lazyRetry(
() => import("./containers/countdown/CountdownContainer")
),
verasity_tokenomics_template: lazy(
verasity_tokenomics_template: lazyRetry(
() => import("./containers/client/VerasityTokenomicsContainer")
),
custom_chart_template: lazy(
custom_chart_template: lazyRetry(
() => import("./containers/custom-modules/CustomChartContainer")
),
custom_card_template: lazy(
custom_card_template: lazyRetry(
() => import("./containers/custom-modules/CustomCardContainer")
),
};
Expand Down
Loading