@livepreso/content-react 0.3.9 → 0.4.0

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/CHANGELOG.json CHANGED
@@ -1,6 +1,18 @@
1
1
  {
2
2
  "name": "@livepreso/content-react",
3
3
  "entries": [
4
+ {
5
+ "version": "0.4.0",
6
+ "tag": "@livepreso/content-react_v0.4.0",
7
+ "date": "Tue, 24 Sep 2024 03:37:23 GMT",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "comment": "Allow overriding react errors"
12
+ }
13
+ ]
14
+ }
15
+ },
4
16
  {
5
17
  "version": "0.3.9",
6
18
  "tag": "@livepreso/content-react_v0.3.9",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Change Log - @livepreso/content-react
2
2
 
3
- This log was last generated on Fri, 23 Aug 2024 05:02:46 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 24 Sep 2024 03:37:23 GMT and should not be manually modified.
4
+
5
+ ## 0.4.0
6
+ Tue, 24 Sep 2024 03:37:23 GMT
7
+
8
+ ### Minor changes
9
+
10
+ - Allow overriding react errors
4
11
 
5
12
  ## 0.3.9
6
13
  Fri, 23 Aug 2024 05:02:46 GMT
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useEffect } from "react";
1
+ import React, { useContext, useEffect, useRef } from "react";
2
2
 
3
3
  import { AppBase } from "@livepreso/content-base";
4
4
  import { CompanywideJSON } from "./lib/components/CompanywideJSON.js";
@@ -7,6 +7,18 @@ import { createRoot } from "react-dom/client";
7
7
  import errorFn from "@livepreso/content-base/error.js";
8
8
  import { useRootSlide } from "./lib/hooks/use-root-slide.js";
9
9
 
10
+ function DefaultErrorComponent({ error }) {
11
+ const slideContext = useContext(SlideContext);
12
+ const ref = useRef();
13
+
14
+ useEffect(() => {
15
+ const errorRenderer = errorFn(error);
16
+ errorRenderer(ref.current, slideContext.slideKey);
17
+ }, []);
18
+
19
+ return <div ref={ref} />;
20
+ }
21
+
10
22
  class ErrorBoundary extends React.Component {
11
23
  static getDerivedStateFromError(error) {
12
24
  return { error, hasError: true };
@@ -19,8 +31,8 @@ class ErrorBoundary extends React.Component {
19
31
 
20
32
  render() {
21
33
  if (this.state.hasError) {
22
- errorFn(this.state.error)(this.props.el);
23
- return null;
34
+ const ErrorComponent = this.props.errorComponent;
35
+ return <ErrorComponent error={this.state.error} />;
24
36
  }
25
37
  return this.props.children;
26
38
  }
@@ -31,6 +43,8 @@ if (module.hot && typeof window.__deck_roots__ === "undefined") {
31
43
  }
32
44
 
33
45
  export class App extends AppBase {
46
+ // can be overridden in subclass
47
+ errorComponent = DefaultErrorComponent;
34
48
  static run(rootApp = null) {
35
49
  const base = new App();
36
50
  if (rootApp) {
@@ -57,8 +71,7 @@ export class App extends AppBase {
57
71
  }
58
72
 
59
73
  const RootApp = this.rootApp(Slide);
60
-
61
- function App() {
74
+ const AppComponent = () => {
62
75
  // TODO: Refactor this to be a prop
63
76
  const slideState = useRootSlide(article);
64
77
 
@@ -80,15 +93,16 @@ export class App extends AppBase {
80
93
  return (
81
94
  <SlideContext.Provider value={slideState}>
82
95
  {!slideState.transitions.exited && (
83
- <ErrorBoundary el={el}>
96
+ // eslint-disable-next-line react/no-this-in-sfc
97
+ <ErrorBoundary errorComponent={this.errorComponent}>
84
98
  <CompanywideJSON>{RootApp}</CompanywideJSON>
85
99
  </ErrorBoundary>
86
100
  )}
87
101
  </SlideContext.Provider>
88
102
  );
89
- }
103
+ };
90
104
 
91
- root.render(<App />);
105
+ root.render(<AppComponent />);
92
106
  }
93
107
 
94
108
  unmountRoot(key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livepreso/content-react",
3
- "version": "0.3.9",
3
+ "version": "0.4.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "publishConfig": {