Fix crash with ModalError

## Issue
There was one instance of ModalError that wasn't wrapped in the Suspense.

## Fix
- Moved `getModal` outside to make the code cleaner. Due to the length of `getModal`, I didn't notice the early return statement.
- Fix ModalError's Suspense.
This commit is contained in:
infinite-persistence 2021-11-03 10:06:57 +08:00
parent bf0aac2339
commit 3d1d448afb
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -97,29 +97,6 @@ const ModalYoutubeWelcome = lazyImport(() =>
import('modal/modalYoutubeWelcome' /* webpackChunkName: "modalYoutubeWelcome" */)
);
type Props = {
modal: { id: string, modalProps: {} },
error: { message: string },
location: { pathname: string },
hideModal: () => void,
};
function ModalRouter(props: Props) {
const { modal, error, location, hideModal } = props;
const { pathname } = location;
React.useEffect(() => {
hideModal();
}, [pathname, hideModal]);
if (error) {
return <ModalError {...error} />;
}
if (!modal) {
return null;
}
function getModal(id) {
switch (id) {
case MODALS.CONFIRM:
@ -213,6 +190,33 @@ function ModalRouter(props: Props) {
}
}
type Props = {
modal: { id: string, modalProps: {} },
error: { message: string },
location: { pathname: string },
hideModal: () => void,
};
function ModalRouter(props: Props) {
const { modal, error, location, hideModal } = props;
const { pathname } = location;
React.useEffect(() => {
hideModal();
}, [pathname, hideModal]);
if (error) {
return (
<React.Suspense fallback={<LoadingBarOneOff />}>
<ModalError {...error} />
</React.Suspense>
);
}
if (!modal) {
return null;
}
const { id, modalProps } = modal;
const SelectedModal = getModal(id);