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

[MPT-52] Mentors: Lazy loading #659

Closed
wants to merge 9 commits into from
Closed
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
10 changes: 7 additions & 3 deletions components/ResultView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { lazy, Suspense } from "react";

import {
red,
Expand All @@ -17,7 +17,7 @@ import {
import { SearchResult } from "@elastic/search-ui";
import { htmlToText } from "html-to-text";

import ResultViewGrid from "./ResultViewGrid";
const LazyResultViewGrid = lazy(() => import("./ResultViewGrid"));
import ResultViewList from "./ResultViewList";

// Performs intelligent snippet truncation by removing leading/trailing periods and
Expand Down Expand Up @@ -158,7 +158,11 @@ const ResultView = ({ result }: { result: SearchResult }) => {
thumbnailImageUrl,
};

return <ResultViewGrid displayResult={displayResult} />;
return (
<Suspense fallback={null}>
<LazyResultViewGrid displayResult={displayResult} />
</Suspense>
);
};

export default ResultView;
Expand Down
11 changes: 8 additions & 3 deletions components/ResultViewGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState, useEffect } from "react";
import React, { useState, useEffect, lazy, Suspense } from "react";
import { Modal, Button, CardActionArea } from "@mui/material";

import type { DisplayResult } from "./ResultView";
import ResultViewList from "./ResultViewList";
const LazyResultViewList = lazy(() => import("./ResultViewList"));

import Card from "@mui/material/Card";
import CardActions from "@mui/material/CardActions";
Expand Down Expand Up @@ -126,7 +126,12 @@ const ResultViewGrid = ({
overflow: "auto",
}}
>
<ResultViewList displayResult={displayResult} isShowReadMore={false} />
<Suspense fallback={null}>
<LazyResultViewList
displayResult={displayResult}
isShowReadMore={false}
/>
</Suspense>
</Modal>
</Card>
);
Expand Down
Loading