Skip to content

Commit 8c37834

Browse files
authored
feat: Error boundary component (#4139)
1 parent 1e59c6b commit 8c37834

File tree

37 files changed

+2154
-129
lines changed

37 files changed

+2154
-129
lines changed

build-tools/utils/pluralize.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const pluralizationMap = {
2828
DatePicker: 'DatePickers',
2929
DateRangePicker: 'DateRangePickers',
3030
Drawer: 'Drawers',
31+
ErrorBoundary: 'ErrorBoundaries',
3132
ExpandableSection: 'ExpandableSections',
3233
FileDropzone: 'FileDropzones',
3334
FileInput: 'FileInputs',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
{
176176
"path": "lib/components/internal/widget-exports.js",
177177
"brotli": false,
178-
"limit": "1100 kB",
178+
"limit": "1150 kB",
179179
"ignore": "react-dom"
180180
}
181181
],

pages/app/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ function isAppLayoutPage(pageId?: string) {
5151
'funnel-analytics/static-single-page-flow',
5252
'funnel-analytics/static-multi-page-flow',
5353
'charts.test',
54+
'error-boundary/demo-async-load',
55+
'error-boundary/demo-components',
5456
];
5557
return pageId !== undefined && appLayoutPages.some(match => pageId.includes(match));
5658
}

pages/app/templates.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React from 'react';
55

66
import { Box, SpaceBetween } from '~components';
77
import I18nProvider, { I18nProviderProps } from '~components/i18n';
8-
import messages from '~components/i18n/messages/all.en';
8+
import messages from '~components/i18n/messages/all.all';
99

1010
import { IframeWrapper } from '../utils/iframe-wrapper';
1111
import ScreenshotArea, { ScreenshotAreaProps } from '../utils/screenshot-area';
@@ -48,7 +48,7 @@ export function SimplePage({ title, subtitle, settings, children, screenshotArea
4848
);
4949

5050
content = i18n ? (
51-
<I18nProvider messages={[messages]} locale="en-GB" {...i18n}>
51+
<I18nProvider messages={[messages]} locale="en" {...i18n}>
5252
{content}
5353
</I18nProvider>
5454
) : (
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import React, { Suspense } from 'react';
5+
6+
import { AppLayout, ContentLayout, ErrorBoundary, Header, Link, Spinner } from '~components';
7+
import I18nProvider from '~components/i18n';
8+
import messages from '~components/i18n/messages/all.en';
9+
10+
function createDelayedResource(ms: number, error: Error) {
11+
let done = false;
12+
const promise = new Promise<void>(resolve =>
13+
setTimeout(() => {
14+
done = true;
15+
resolve();
16+
}, ms)
17+
);
18+
return {
19+
read() {
20+
if (!done) {
21+
throw promise;
22+
}
23+
throw error;
24+
},
25+
};
26+
}
27+
28+
const resource = createDelayedResource(2000, new Error('Async page load failed'));
29+
30+
function AsyncFailingPage() {
31+
resource.read();
32+
return <div>Loaded page</div>;
33+
}
34+
35+
export default function ErrorBoundaryAsyncDemo() {
36+
return (
37+
<I18nProvider messages={[messages]} locale="en">
38+
<ErrorBoundary
39+
onError={({ error }) => console.log(`Error "${error.message.slice(0, 20)}… reported."`)}
40+
i18nStrings={{ components: { Feedback: Link } }}
41+
>
42+
<AppLayout
43+
navigationHide={false}
44+
toolsHide={false}
45+
content={
46+
<Suspense
47+
fallback={
48+
<ContentLayout header={<Header variant="h1">Error boundaries async</Header>}>
49+
<Spinner size="large" />
50+
</ContentLayout>
51+
}
52+
>
53+
<AsyncFailingPage />
54+
</Suspense>
55+
}
56+
/>
57+
</ErrorBoundary>
58+
</I18nProvider>
59+
);
60+
}

0 commit comments

Comments
 (0)