Skip to content

Commit a329588

Browse files
feat: add link to low vram guide to OOM toast (local only)
Needed to do a bit of refactoring to support this. Overall, the error toast components are easier to understand now.
1 parent e09cf64 commit a329588

File tree

4 files changed

+50
-49
lines changed

4 files changed

+50
-49
lines changed

invokeai/frontend/web/public/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,7 @@
11851185
"modelAddedSimple": "Model Added to Queue",
11861186
"modelImportCanceled": "Model Import Canceled",
11871187
"outOfMemoryError": "Out of Memory Error",
1188+
"outOfMemoryErrorDescLocal": "Follow our <LinkComponent>Low VRAM guide</LinkComponent> to reduce OOMs.",
11881189
"outOfMemoryErrorDesc": "Your current generation settings exceed system capacity. Please adjust your settings and try again.",
11891190
"parameters": "Parameters",
11901191
"parameterSet": "Parameter Recalled",
@@ -2133,7 +2134,7 @@
21332134
"toGetStartedLocal": "To get started, make sure to download or import models needed to run Invoke. Then, enter a prompt in the box and click <StrongComponent>Invoke</StrongComponent> to generate your first image. Select a prompt template to improve results. You can choose to save your images directly to the <StrongComponent>Gallery</StrongComponent> or edit them to the <StrongComponent>Canvas</StrongComponent>.",
21342135
"toGetStarted": "To get started, enter a prompt in the box and click <StrongComponent>Invoke</StrongComponent> to generate your first image. Select a prompt template to improve results. You can choose to save your images directly to the <StrongComponent>Gallery</StrongComponent> or edit them to the <StrongComponent>Canvas</StrongComponent>.",
21352136
"gettingStartedSeries": "Want more guidance? Check out our <LinkComponent>Getting Started Series</LinkComponent> for tips on unlocking the full potential of the Invoke Studio.",
2136-
"lowVRAMMode": "For best performance, follow our <LinkComponent>Low VRAM mode guide</LinkComponent>.",
2137+
"lowVRAMMode": "For best performance, follow our <LinkComponent>Low VRAM guide</LinkComponent>.",
21372138
"noModelsInstalled": "It looks like you don't have any models installed! You can <DownloadStarterModelsButton>download a starter model bundle</DownloadStarterModelsButton> or <ImportModelsButton>import models</ImportModelsButton>."
21382139
},
21392140
"whatsNew": {

invokeai/frontend/web/src/features/gallery/components/ImageViewer/NoContentForViewer.tsx

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
import {
2-
Alert,
3-
AlertDescription,
4-
AlertIcon,
5-
Button,
6-
Divider,
7-
Flex,
8-
Icon,
9-
Link,
10-
Spinner,
11-
Text,
12-
} from '@invoke-ai/ui-library';
1+
import type { ButtonProps } from '@invoke-ai/ui-library';
2+
import { Alert, AlertDescription, AlertIcon, Button, Divider, Flex, Link, Spinner, Text } from '@invoke-ai/ui-library';
133
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
144
import { IAINoContentFallback } from 'common/components/IAIImageFallback';
155
import { InvokeLogoIcon } from 'common/components/InvokeLogoIcon';
@@ -71,20 +61,19 @@ const LoadingSpinner = () => {
7161
);
7262
};
7363

74-
const ExternalLink = (props: PropsWithChildren<{ href: string }>) => {
64+
export const ExternalLink = (props: ButtonProps & { href: string }) => {
7565
return (
7666
<Button
7767
as={Link}
78-
variant="link"
68+
variant="unstyled"
7969
isExternal
8070
display="inline-flex"
8171
alignItems="center"
82-
href={props.href}
72+
rightIcon={<PiArrowSquareOutBold />}
8373
color="base.50"
84-
>
85-
{props.children}
86-
<Icon display="inline" verticalAlign="middle" marginInlineStart={2} as={PiArrowSquareOutBold} />
87-
</Button>
74+
mt={-1}
75+
{...props}
76+
/>
8877
);
8978
};
9079

invokeai/frontend/web/src/features/toast/ErrorToastDescription.tsx

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
11
import { Flex, IconButton, Text } from '@invoke-ai/ui-library';
2-
import { t } from 'i18next';
3-
import { useMemo } from 'react';
4-
import { useTranslation } from 'react-i18next';
2+
import { ExternalLink } from 'features/gallery/components/ImageViewer/NoContentForViewer';
3+
import { useCallback, useMemo } from 'react';
4+
import { Trans, useTranslation } from 'react-i18next';
55
import { PiCopyBold } from 'react-icons/pi';
66

7-
function onCopy(sessionId: string) {
8-
navigator.clipboard.writeText(sessionId);
9-
}
7+
type Props = { errorType: string; errorMessage?: string | null; sessionId: string; isLocal: boolean };
108

11-
const ERROR_TYPE_TO_TITLE: Record<string, string> = {
12-
OutOfMemoryError: 'toast.outOfMemoryError',
13-
};
9+
export const ErrorToastTitle = ({ errorType }: Props) => {
10+
const { t } = useTranslation();
1411

15-
const COMMERCIAL_ERROR_TYPE_TO_DESC: Record<string, string> = {
16-
OutOfMemoryError: 'toast.outOfMemoryErrorDesc',
17-
};
12+
if (errorType === 'OutOfMemoryError') {
13+
return t('toast.outOfMemoryError');
14+
}
1815

19-
export const getTitleFromErrorType = (errorType: string) => {
20-
return t(ERROR_TYPE_TO_TITLE[errorType] ?? 'toast.serverError');
16+
return t('toast.serverError');
2117
};
2218

23-
type Props = { errorType: string; errorMessage?: string | null; sessionId: string; isLocal: boolean };
24-
25-
export default function ErrorToastDescription({ errorType, errorMessage, sessionId, isLocal }: Props) {
19+
export default function ErrorToastDescription({ errorType, isLocal, sessionId, errorMessage }: Props) {
2620
const { t } = useTranslation();
21+
2722
const description = useMemo(() => {
28-
// Special handling for commercial error types
29-
const descriptionTKey = isLocal ? null : COMMERCIAL_ERROR_TYPE_TO_DESC[errorType];
30-
if (descriptionTKey) {
31-
return t(descriptionTKey);
32-
}
33-
if (errorMessage) {
23+
if (errorType === 'OutOfMemoryError') {
24+
if (isLocal) {
25+
return (
26+
<Trans
27+
i18nKey="toast.outOfMemoryErrorDescLocal"
28+
components={{
29+
LinkComponent: <ExternalLink href="https://invoke-ai.github.io/InvokeAI/features/low-vram/" />,
30+
}}
31+
/>
32+
);
33+
} else {
34+
return t('toast.outOfMemoryErrorDesc');
35+
}
36+
} else if (errorMessage) {
3437
return `${errorType}: ${errorMessage}`;
3538
}
3639
}, [errorMessage, errorType, isLocal, t]);
40+
41+
const copySessionId = useCallback(() => navigator.clipboard.writeText(sessionId), [sessionId]);
42+
3743
return (
3844
<Flex flexDir="column">
3945
{description && (
@@ -50,14 +56,12 @@ export default function ErrorToastDescription({ errorType, errorMessage, session
5056
size="sm"
5157
aria-label="Copy"
5258
icon={<PiCopyBold />}
53-
onClick={onCopy.bind(null, sessionId)}
59+
onClick={copySessionId}
5460
variant="ghost"
55-
sx={sx}
61+
sx={{ svg: { fill: 'base.50' } }}
5662
/>
5763
</Flex>
5864
)}
5965
</Flex>
6066
);
6167
}
62-
63-
const sx = { svg: { fill: 'base.50' } };

invokeai/frontend/web/src/services/events/setEventListeners.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { AppStore } from 'app/store/store';
88
import { deepClone } from 'common/util/deepClone';
99
import { $nodeExecutionStates, upsertExecutionState } from 'features/nodes/hooks/useExecutionState';
1010
import { zNodeStatus } from 'features/nodes/types/invocation';
11-
import ErrorToastDescription, { getTitleFromErrorType } from 'features/toast/ErrorToastDescription';
11+
import ErrorToastDescription, { ErrorToastTitle } from 'features/toast/ErrorToastDescription';
1212
import { toast } from 'features/toast/toast';
1313
import { t } from 'i18next';
1414
import { forEach, isNil, round } from 'lodash-es';
@@ -400,7 +400,14 @@ export const setEventListeners = ({ socket, store, setIsConnected }: SetEventLis
400400

401401
toast({
402402
id: `INVOCATION_ERROR_${error_type}`,
403-
title: getTitleFromErrorType(error_type),
403+
title: (
404+
<ErrorToastTitle
405+
errorType={error_type}
406+
errorMessage={error_message}
407+
sessionId={sessionId}
408+
isLocal={isLocal}
409+
/>
410+
),
404411
status: 'error',
405412
duration: null,
406413
updateDescription: isLocal,

0 commit comments

Comments
 (0)