Skip to content

Commit bf2127a

Browse files
Trying an error in prod 🤠
1 parent e0ad923 commit bf2127a

File tree

16 files changed

+85
-16
lines changed

16 files changed

+85
-16
lines changed

src/App.jsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import About from './components/About'
22
import Acclaim from './components/Acclaim'
3+
import ErrorBoundary from './components/ErrorBoundary'
34
import Experience from './components/Experience'
45
import Footer from './components/Footer'
56
import Header from './components/Header'
@@ -8,7 +9,7 @@ import Skills from './components/Skills'
89

910
const App = () => {
1011
return (
11-
<div>
12+
<ErrorBoundary>
1213
<Header />
1314
<main>
1415
<About />
@@ -18,7 +19,7 @@ const App = () => {
1819
<Publications />
1920
</main>
2021
<Footer />
21-
</div>
22+
</ErrorBoundary>
2223
)
2324
}
2425

src/components/About/About.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import avatar01 from './images/01.png?width=230'
33
import { about, author } from 'site-config'
44

55
const About = () => {
6+
throw new Error('🌶️🌶️😉')
67
return (
78
<div className={styles.blurb}>
89
<picture>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Component } from 'react'
2+
import PropTypes from 'prop-types'
3+
import styles from './ErrorBoundary.module.css'
4+
5+
class ErrorBoundary extends Component {
6+
constructor(props) {
7+
super(props)
8+
this.state = {
9+
hasError: false,
10+
error: null,
11+
}
12+
}
13+
14+
static getDerivedStateFromError(error) {
15+
return { hasError: true, error }
16+
}
17+
18+
/**
19+
* @param {Error} error
20+
* @param {import('react').ErrorInfo} errorInfo
21+
*/
22+
componentDidCatch(error, errorInfo) {
23+
console.error(error, errorInfo)
24+
}
25+
26+
render() {
27+
if (this.state.hasError) {
28+
return (
29+
<div className={styles.error}>
30+
<div>
31+
<strong>
32+
{this.state.error.name} :{this.state.error.message}
33+
</strong>
34+
</div>
35+
{this.state.error.stack && <pre>{this.state.error.stack}</pre>}
36+
</div>
37+
)
38+
}
39+
return this.props.children
40+
}
41+
}
42+
43+
ErrorBoundary.propTypes = {
44+
children: PropTypes.node.isRequired,
45+
}
46+
47+
export default ErrorBoundary
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@value vars: "../../variables.module.css";
2+
@value surface100, surfacemixed600, containerwidth from vars;
3+
4+
.error {
5+
background-color: surfacemixed600;
6+
padding: 2em;
7+
width: 100%;
8+
height: 100%;
9+
}
10+
11+
.error pre {
12+
font-size: medium;
13+
}
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import ErrorBoundary from './ErrorBoundary'
2+
export default ErrorBoundary

src/components/Footer/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { default as Footer } from './Footer'
1+
import Footer from './Footer'
22

33
export default Footer

src/components/Header/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { default as Header } from './Header'
1+
import Header from './Header'
22

33
export default Header

src/components/Icon/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { default as Icon } from './Icon'
1+
import Icon from './Icon'
22

33
export default Icon

src/components/Loader/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { default as Loader } from './Loader'
1+
import Loader from './Loader'
22

33
export default Loader
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { default as Entry } from './Entry'
1+
import Entry from './Entry'
22

33
export default Entry

src/components/Publications/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { default as Publications } from './Publications'
1+
import Publications from './Publications'
22

33
export default Publications

src/components/Skills/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { default as Skills } from './Skills'
1+
import Skills from './Skills'
22

33
export default Skills

src/components/Socials/index.js

-3
This file was deleted.

src/components/Socials/index.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Socials from './Socials'
2+
3+
export default Socials

src/index.jsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { StrictMode, Suspense, lazy } from 'react'
22
import { createRoot } from 'react-dom/client'
3+
import ErrorBoundary from './components/ErrorBoundary'
34
import Loader from './components/Loader'
45
import './index.module.css'
56

@@ -9,8 +10,10 @@ const root = createRoot(node)
910

1011
root.render(
1112
<StrictMode>
12-
<Suspense fallback={<Loader />}>
13-
<App />
14-
</Suspense>
13+
<ErrorBoundary>
14+
<Suspense fallback={<Loader />}>
15+
<App />
16+
</Suspense>
17+
</ErrorBoundary>
1518
</StrictMode>,
1619
)

src/index.module.css

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ strong {
9191
font-weight: 500;
9292
}
9393

94-
#root {
94+
:global #root {
9595
isolation: isolate;
96+
width: 100vw;
97+
height: 100vh;
9698
}
9799

98100
:global .container {

0 commit comments

Comments
 (0)