Skip to content

Commit e2f3274

Browse files
authored
refactor: initial-chunk-retry and async-chunk-retry should reuse the same default runtime options (#14)
* refactor: initial-chunk-retry and async-chunk-retry should reuse the same default runtime options * chore: update * chore: update
1 parent 21a5863 commit e2f3274

17 files changed

+195
-118
lines changed

playground/rsbuild.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineConfig } from '@rsbuild/core';
2+
import { pluginReact } from '@rsbuild/plugin-react';
23
import { pluginAssetsRetry } from '../dist';
34

45
export default defineConfig({
5-
plugins: [pluginAssetsRetry()],
6+
plugins: [pluginAssetsRetry(), pluginReact()],
67
});

playground/src/App.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
body {
2+
margin: 0;
3+
color: #fff;
4+
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
5+
background-image: linear-gradient(to bottom, #020917, #101725);
6+
}

playground/src/App.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import './App.css';
3+
import CompTest from './CompTest';
4+
import { ErrorBoundary } from './ErrorBoundary';
5+
6+
const AsyncCompTest = React.lazy(() => import('./AsyncCompTest'));
7+
8+
const App = () => {
9+
return (
10+
<div className="content">
11+
<div style={{ border: '1px solid white', padding: 20 }}>
12+
<ErrorBoundary elementId="comp-test-error">
13+
<CompTest />
14+
</ErrorBoundary>
15+
</div>
16+
<div style={{ border: '1px solid white', padding: 20 }}>
17+
<ErrorBoundary elementId="async-comp-test-error">
18+
<AsyncCompTest />
19+
</ErrorBoundary>
20+
</div>
21+
</div>
22+
);
23+
};
24+
25+
export default App;

playground/src/AsyncCompTest.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#async-comp-test {
2+
color: white;
3+
background-color: darkblue;
4+
}

playground/src/AsyncCompTest.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import './AsyncCompTest.css';
2+
3+
export default function AsyncCompTest() {
4+
return <div id="async-comp-test">Hello AsyncCompTest</div>;
5+
}

playground/src/CompTest.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#comp-test {
2+
color: white;
3+
background-color: darkblue;
4+
}

playground/src/CompTest.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import './CompTest.css';
2+
3+
export default function CompTest() {
4+
return <div id="comp-test">Hello CompTest</div>;
5+
}

playground/src/ErrorBoundary.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
3+
interface Props {
4+
elementId: string;
5+
children: React.ReactNode;
6+
}
7+
8+
class ErrorBoundary extends React.Component<
9+
Props,
10+
{ hasError: boolean; error: null | Error },
11+
unknown
12+
> {
13+
constructor(props: Props) {
14+
super(props);
15+
this.state = { hasError: false, error: null };
16+
}
17+
18+
static getDerivedStateFromError(error: Error) {
19+
return { hasError: true, error };
20+
}
21+
22+
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
23+
console.log(error, errorInfo);
24+
}
25+
26+
render() {
27+
if (this.state.hasError) {
28+
return (
29+
<pre id={this.props.elementId}>{this.state?.error?.toString()}</pre>
30+
);
31+
}
32+
33+
return this.props.children;
34+
}
35+
}
36+
37+
export { ErrorBoundary };

playground/src/index.css

Lines changed: 0 additions & 26 deletions
This file was deleted.

playground/src/index.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)