Improve reliability by retrying failed imports (#5408)

This commit is contained in:
Tom Moor
2023-06-03 14:17:36 -04:00
committed by GitHub
parent a8a506af3e
commit d18994b14e
10 changed files with 74 additions and 25 deletions

View File

@@ -15,6 +15,7 @@ import type { Editor as TEditor } from "~/editor";
import usePolicy from "~/hooks/usePolicy";
import useStores from "~/hooks/useStores";
import history from "~/utils/history";
import lazyWithRetry from "~/utils/lazyWithRetry";
import {
searchPath,
newDocumentPath,
@@ -25,16 +26,16 @@ import {
} from "~/utils/routeHelpers";
import Fade from "./Fade";
const DocumentComments = React.lazy(
const DocumentComments = lazyWithRetry(
() => import("~/scenes/Document/components/Comments")
);
const DocumentHistory = React.lazy(
const DocumentHistory = lazyWithRetry(
() => import("~/scenes/Document/components/History")
);
const DocumentInsights = React.lazy(
const DocumentInsights = lazyWithRetry(
() => import("~/scenes/Document/components/Insights")
);
const CommandBar = React.lazy(() => import("~/components/CommandBar"));
const CommandBar = lazyWithRetry(() => import("~/components/CommandBar"));
const AuthenticatedLayout: React.FC = ({ children }) => {
const { ui, auth } = useStores();

View File

@@ -26,11 +26,12 @@ import useToasts from "~/hooks/useToasts";
import { NotFoundError } from "~/utils/errors";
import { uploadFile } from "~/utils/files";
import { isModKey } from "~/utils/keyboard";
import lazyWithRetry from "~/utils/lazyWithRetry";
import { sharedDocumentPath } from "~/utils/routeHelpers";
import { isHash } from "~/utils/urls";
import DocumentBreadcrumb from "./DocumentBreadcrumb";
const LazyLoadedEditor = React.lazy(() => import("~/editor"));
const LazyLoadedEditor = lazyWithRetry(() => import("~/editor"));
export type Props = Optional<
EditorProps,

View File

@@ -47,6 +47,7 @@ import Flex from "~/components/Flex";
import { LabelText } from "~/components/Input";
import NudeButton from "~/components/NudeButton";
import Text from "~/components/Text";
import lazyWithRetry from "~/utils/lazyWithRetry";
import DelayedMount from "./DelayedMount";
const style = {
@@ -54,7 +55,7 @@ const style = {
height: 30,
};
const TwitterPicker = React.lazy(
const TwitterPicker = lazyWithRetry(
() => import("react-color/lib/components/twitter/Twitter")
);

View File

@@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";
import { MenuButton, useMenuState } from "reakit/Menu";
import styled from "styled-components";
import { s } from "@shared/styles";
import lazyWithRetry from "~/utils/lazyWithRetry";
import ContextMenu from "./ContextMenu";
import DelayedMount from "./DelayedMount";
import Input, { Props as InputProps } from "./Input";
@@ -68,7 +69,7 @@ const SwatchButton = styled(NudeButton)<{ $background: string | undefined }>`
right: 6px;
`;
const ColorPicker = React.lazy(
const ColorPicker = lazyWithRetry(
() => import("react-color/lib/components/chrome/Chrome")
);

View File

@@ -3,9 +3,10 @@ import * as React from "react";
import { useHistory, useLocation } from "react-router-dom";
import scrollIntoView from "smooth-scroll-into-view-if-needed";
import useQuery from "~/hooks/useQuery";
import lazyWithRetry from "~/utils/lazyWithRetry";
import type { Props } from "./Table";
const Table = React.lazy(() => import("~/components/Table"));
const Table = lazyWithRetry(() => import("~/components/Table"));
const TableFromParams = (
props: Omit<Props, "onChangeSort" | "onChangePage" | "topRef">

View File

@@ -1,7 +1,8 @@
import { formatDistanceToNow } from "date-fns";
import * as React from "react";
import lazyWithRetry from "~/utils/lazyWithRetry";
const LocaleTime = React.lazy(() => import("~/components/LocaleTime"));
const LocaleTime = lazyWithRetry(() => import("~/components/LocaleTime"));
type Props = React.ComponentProps<typeof LocaleTime> & {
onClick?: () => void;