Skip to content

Commit 720060d

Browse files
committed
poc
1 parent a4a22ce commit 720060d

File tree

25 files changed

+1260
-121
lines changed

25 files changed

+1260
-121
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
{
178178
"path": "lib/components/internal/widget-exports.js",
179179
"brotli": false,
180-
"limit": "960 kB",
180+
"limit": "1000 kB",
181181
"ignore": "react-dom"
182182
}
183183
],

pages/app/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function isAppLayoutPage(pageId?: string) {
5050
'prompt-input/simple',
5151
'funnel-analytics/static-single-page-flow',
5252
'funnel-analytics/static-multi-page-flow',
53+
'error-boundary',
5354
];
5455
return pageId !== undefined && appLayoutPages.some(match => pageId.includes(match));
5556
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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, Box, ErrorBoundary, Spinner } from '~components';
7+
import I18nProvider from '~components/i18n';
8+
import messages from '~components/i18n/messages/all.en';
9+
10+
import ScreenshotArea from '../utils/screenshot-area';
11+
12+
function createDelayedResource(ms: number, error: Error) {
13+
let done = false;
14+
const promise = new Promise<void>(resolve =>
15+
setTimeout(() => {
16+
done = true;
17+
resolve();
18+
}, ms)
19+
);
20+
return {
21+
read() {
22+
if (!done) {
23+
throw promise;
24+
}
25+
throw error;
26+
},
27+
};
28+
}
29+
30+
const resource = createDelayedResource(2000, new Error('Async page load failed'));
31+
32+
function AsyncFailingPage() {
33+
resource.read();
34+
return <div>Loaded page</div>;
35+
}
36+
37+
export default function ErrorBoundaryAsyncDemo() {
38+
return (
39+
<ScreenshotArea gutters={false}>
40+
<I18nProvider messages={[messages]} locale="en">
41+
<ErrorBoundary
42+
onError={error => console.log(`Error "${error.message.slice(0, 20)}… reported."`)}
43+
feedback={{ href: '#' }}
44+
>
45+
{/* AppLayout remains synchronous */}
46+
<AppLayout
47+
navigationHide={false}
48+
toolsHide={false}
49+
tools={<Box>Tools content</Box>}
50+
navigation={<Box>Navigation content</Box>}
51+
content={
52+
<Suspense fallback={<Fallback />}>
53+
<AsyncFailingPage />
54+
</Suspense>
55+
}
56+
/>
57+
</ErrorBoundary>
58+
</I18nProvider>
59+
</ScreenshotArea>
60+
);
61+
}
62+
63+
function Fallback() {
64+
return (
65+
<div style={{ width: '100%', display: 'flex', justifyContent: 'center' }}>
66+
<Spinner size="large" />
67+
</div>
68+
);
69+
}

0 commit comments

Comments
 (0)