@embeddable.com/sdk-react 2.2.3 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embeddable.com/sdk-react",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "Embeddable SDK React plugin responsible for React components bundling.",
5
5
  "keywords": [
6
6
  "embeddable",
@@ -1,4 +1,5 @@
1
1
  import 'vite/modulepreload-polyfill';
2
+ {{ERROR_FALLBACK_COMPONENT_IMPORT}}
2
3
 
3
4
  import React from 'react';
4
5
  import ReactDOM from 'react-dom/client';
@@ -15,9 +16,32 @@ export default (rootEl, componentName, props) => {
15
16
  rootEl.removeEventListener('EMBEDDABLE_COMPONENT:UNMOUNT', unmountHandler);
16
17
  };
17
18
  root.render(
19
+ <ErrorBoundary fallback={{{ERROR_FALLBACK_COMPONENT}}}>
18
20
  <React.Suspense fallback={<div/>}>
19
21
  <Component {...props} propsUpdateListener={rootEl} />
20
22
  </React.Suspense>
23
+ </ErrorBoundary>
21
24
  );
22
25
  rootEl.addEventListener('EMBEDDABLE_COMPONENT:UNMOUNT', unmountHandler);
26
+ }
27
+
28
+ class ErrorBoundary extends React.Component {
29
+ constructor(props) {
30
+ super(props);
31
+ this.state = { hasError: false };
32
+ }
33
+
34
+ static getDerivedStateFromError(error) {
35
+ // Update state so the next render will show the fallback UI.
36
+ return { hasError: true, error };
37
+ }
38
+
39
+ render() {
40
+ if (this.state.hasError && this.props.fallback) {
41
+ const FallbackComponent = this.props.fallback;
42
+ return <FallbackComponent error={this.state.error} />
43
+ }
44
+
45
+ return this.props.children;
46
+ }
23
47
  }