Skip to content

Commit

Permalink
feat: lazy loading (#659)
Browse files Browse the repository at this point in the history
Co-authored-by: M. Allen Jeffrey <[email protected]>
  • Loading branch information
wei2912 and jeffzy15 committed Jan 4, 2024
1 parent 4a5b781 commit eaf3b91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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"));

// Performs intelligent snippet truncation by removing leading/trailing periods and
// whitespace, and filling with ellipsis accordingly.
Expand Down Expand Up @@ -161,7 +161,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 @@ -128,7 +128,12 @@ const ResultViewGrid = ({
overflow: "auto",
}}
>
<ResultViewList displayResult={displayResult} isShowReadMore={false} />
<Suspense fallback={null}>
<LazyResultViewList
displayResult={displayResult}
isShowReadMore={false}
/>
</Suspense>
</Modal>
</Card>
);
Expand Down

0 comments on commit eaf3b91

Please sign in to comment.