@sitecore-jss/sitecore-jss-react 22.1.0-canary.6 → 22.1.0-canary.8

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.
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const react_1 = __importStar(require("react"));
27
+ const withSitecoreContext_1 = require("../enhancers/withSitecoreContext");
28
+ class ErrorBoundary extends react_1.default.Component {
29
+ constructor(props) {
30
+ super(props);
31
+ this.defaultErrorMessage = 'There was a problem loading this section.'; // eslint-disable-line
32
+ this.defaultLoadingMessage = 'Loading component...';
33
+ this.state = { error: null };
34
+ }
35
+ static getDerivedStateFromError(error) {
36
+ return { error: error };
37
+ }
38
+ componentDidCatch(error, errorInfo) {
39
+ console.error({ error, errorInfo });
40
+ }
41
+ isInDevMode() {
42
+ return process.env.NODE_ENV === 'development';
43
+ }
44
+ render() {
45
+ var _a, _b;
46
+ if (this.state.error) {
47
+ if (this.props.customErrorComponent) {
48
+ return react_1.default.createElement(this.props.customErrorComponent, { error: this.state.error });
49
+ }
50
+ else {
51
+ if (this.isInDevMode() || ((_a = this.props.sitecoreContext) === null || _a === void 0 ? void 0 : _a.pageEditing)) {
52
+ return (react_1.default.createElement("div", null,
53
+ react_1.default.createElement("div", { className: "sc-jss-placeholder-error" },
54
+ "A rendering error occurred in component",
55
+ ' ',
56
+ react_1.default.createElement("em", null, (_b = this.props.rendering) === null || _b === void 0 ? void 0 : _b.componentName),
57
+ react_1.default.createElement("br", null),
58
+ "Error: ",
59
+ react_1.default.createElement("em", null, this.state.error.message))));
60
+ }
61
+ else {
62
+ return (react_1.default.createElement("div", null,
63
+ react_1.default.createElement("div", { className: "sc-jss-placeholder-error" }, this.defaultErrorMessage)));
64
+ }
65
+ }
66
+ }
67
+ return (react_1.default.createElement(react_1.Suspense, { fallback: react_1.default.createElement("h4", null, this.props.componentLoadingMessage || this.defaultLoadingMessage) }, this.props.children));
68
+ }
69
+ }
70
+ exports.default = (0, withSitecoreContext_1.withSitecoreContext)()(ErrorBoundary);
@@ -24,6 +24,7 @@ const FEaaSComponent_1 = require("./FEaaSComponent");
24
24
  const FEaaSWrapper_1 = require("./FEaaSWrapper");
25
25
  const BYOCComponent_1 = require("./BYOCComponent");
26
26
  const BYOCWrapper_1 = require("./BYOCWrapper");
27
+ const ErrorBoundary_1 = __importDefault(require("./ErrorBoundary"));
27
28
  class PlaceholderCommon extends react_1.default.Component {
28
29
  constructor(props) {
29
30
  super(props);
@@ -126,7 +127,12 @@ class PlaceholderCommon extends react_1.default.Component {
126
127
  })), { rendering: componentRendering });
127
128
  return react_1.default.createElement(component, this.props.modifyComponentProps ? this.props.modifyComponentProps(finalProps) : finalProps);
128
129
  })
129
- .filter((element) => element); // remove nulls
130
+ .filter((element) => element)
131
+ .map((element, id) => {
132
+ // assign type based on passed element - type='text/sitecore' should be ignored when renderEach Placeholder prop function is being used
133
+ const type = element.props.type === 'text/sitecore' ? element.props.type : '';
134
+ return (react_1.default.createElement(ErrorBoundary_1.default, { key: element.type + '-' + id, customErrorComponent: this.props.errorComponent, rendering: element.props.rendering, componentLoadingMessage: this.props.componentLoadingMessage, type: type }, element));
135
+ });
130
136
  }
131
137
  getComponentForRendering(renderingDefinition) {
132
138
  var _a;
@@ -0,0 +1,45 @@
1
+ import React, { Suspense } from 'react';
2
+ import { withSitecoreContext } from '../enhancers/withSitecoreContext';
3
+ class ErrorBoundary extends React.Component {
4
+ constructor(props) {
5
+ super(props);
6
+ this.defaultErrorMessage = 'There was a problem loading this section.'; // eslint-disable-line
7
+ this.defaultLoadingMessage = 'Loading component...';
8
+ this.state = { error: null };
9
+ }
10
+ static getDerivedStateFromError(error) {
11
+ return { error: error };
12
+ }
13
+ componentDidCatch(error, errorInfo) {
14
+ console.error({ error, errorInfo });
15
+ }
16
+ isInDevMode() {
17
+ return process.env.NODE_ENV === 'development';
18
+ }
19
+ render() {
20
+ var _a, _b;
21
+ if (this.state.error) {
22
+ if (this.props.customErrorComponent) {
23
+ return React.createElement(this.props.customErrorComponent, { error: this.state.error });
24
+ }
25
+ else {
26
+ if (this.isInDevMode() || ((_a = this.props.sitecoreContext) === null || _a === void 0 ? void 0 : _a.pageEditing)) {
27
+ return (React.createElement("div", null,
28
+ React.createElement("div", { className: "sc-jss-placeholder-error" },
29
+ "A rendering error occurred in component",
30
+ ' ',
31
+ React.createElement("em", null, (_b = this.props.rendering) === null || _b === void 0 ? void 0 : _b.componentName),
32
+ React.createElement("br", null),
33
+ "Error: ",
34
+ React.createElement("em", null, this.state.error.message))));
35
+ }
36
+ else {
37
+ return (React.createElement("div", null,
38
+ React.createElement("div", { className: "sc-jss-placeholder-error" }, this.defaultErrorMessage)));
39
+ }
40
+ }
41
+ }
42
+ return (React.createElement(Suspense, { fallback: React.createElement("h4", null, this.props.componentLoadingMessage || this.defaultLoadingMessage) }, this.props.children));
43
+ }
44
+ }
45
+ export default withSitecoreContext()(ErrorBoundary);
@@ -18,6 +18,7 @@ import { FEaaSComponent, FEAAS_COMPONENT_RENDERING_NAME } from './FEaaSComponent
18
18
  import { FEaaSWrapper, FEAAS_WRAPPER_RENDERING_NAME } from './FEaaSWrapper';
19
19
  import { BYOCComponent, BYOC_COMPONENT_RENDERING_NAME } from './BYOCComponent';
20
20
  import { BYOCWrapper, BYOC_WRAPPER_RENDERING_NAME } from './BYOCWrapper';
21
+ import ErrorBoundary from './ErrorBoundary';
21
22
  export class PlaceholderCommon extends React.Component {
22
23
  constructor(props) {
23
24
  super(props);
@@ -120,7 +121,12 @@ export class PlaceholderCommon extends React.Component {
120
121
  })), { rendering: componentRendering });
121
122
  return React.createElement(component, this.props.modifyComponentProps ? this.props.modifyComponentProps(finalProps) : finalProps);
122
123
  })
123
- .filter((element) => element); // remove nulls
124
+ .filter((element) => element)
125
+ .map((element, id) => {
126
+ // assign type based on passed element - type='text/sitecore' should be ignored when renderEach Placeholder prop function is being used
127
+ const type = element.props.type === 'text/sitecore' ? element.props.type : '';
128
+ return (React.createElement(ErrorBoundary, { key: element.type + '-' + id, customErrorComponent: this.props.errorComponent, rendering: element.props.rendering, componentLoadingMessage: this.props.componentLoadingMessage, type: type }, element));
129
+ });
124
130
  }
125
131
  getComponentForRendering(renderingDefinition) {
126
132
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-react",
3
- "version": "22.1.0-canary.6",
3
+ "version": "22.1.0-canary.8",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -61,14 +61,14 @@
61
61
  "react-dom": "^18.2.0"
62
62
  },
63
63
  "dependencies": {
64
- "@sitecore-jss/sitecore-jss": "^22.1.0-canary.6",
64
+ "@sitecore-jss/sitecore-jss": "^22.1.0-canary.8",
65
65
  "fast-deep-equal": "^3.1.3",
66
66
  "prop-types": "^15.8.1",
67
67
  "style-attr": "^1.3.0"
68
68
  },
69
69
  "description": "",
70
70
  "types": "types/index.d.ts",
71
- "gitHead": "09561a04bef1c889ebe3c999ad61040f059eed57",
71
+ "gitHead": "74bfc5998039cdc358f5e715febb54997fcd7ef1",
72
72
  "files": [
73
73
  "dist",
74
74
  "types"
@@ -0,0 +1,17 @@
1
+ /// <reference types="@types/react" />
2
+ import React, { ReactNode } from 'react';
3
+ import { ComponentRendering } from '@sitecore-jss/sitecore-jss/layout';
4
+ import { SitecoreContextValue } from './SitecoreContext';
5
+ type CustomErrorComponentProps = {
6
+ [prop: string]: unknown;
7
+ };
8
+ export type ErrorBoundaryProps = {
9
+ children: ReactNode;
10
+ sitecoreContext: SitecoreContextValue;
11
+ type: string;
12
+ customErrorComponent?: React.ComponentClass<CustomErrorComponentProps> | React.FC<CustomErrorComponentProps>;
13
+ rendering?: ComponentRendering;
14
+ componentLoadingMessage?: string;
15
+ };
16
+ declare const _default: (props: import("../enhancers/withSitecoreContext").WithSitecoreContextHocProps<ErrorBoundaryProps>) => React.JSX.Element;
17
+ export default _default;
@@ -57,6 +57,10 @@ export interface PlaceholderProps {
57
57
  * the placeholder
58
58
  */
59
59
  errorComponent?: React.ComponentClass<ErrorComponentProps> | React.FC<ErrorComponentProps>;
60
+ /**
61
+ * The message that gets displayed while component is loading
62
+ */
63
+ componentLoadingMessage?: string;
60
64
  }
61
65
  export declare class PlaceholderCommon<T extends PlaceholderProps> extends React.Component<T> {
62
66
  static propTypes: {
@@ -86,9 +90,7 @@ export declare class PlaceholderCommon<T extends PlaceholderProps> extends React
86
90
  } | {
87
91
  styles: string;
88
92
  };
89
- getComponentsForRenderingData(placeholderData: (ComponentRendering | HtmlElementRendering)[]): React.ReactElement<{
90
- [attr: string]: unknown;
91
- }, string | React.JSXElementConstructor<any>>[];
93
+ getComponentsForRenderingData(placeholderData: (ComponentRendering | HtmlElementRendering)[]): React.JSX.Element[];
92
94
  getComponentForRendering(renderingDefinition: ComponentRendering): ComponentType | null;
93
95
  addRef(nodeRef: Element): void;
94
96
  createRawElement(elem: HtmlElementRendering, baseProps: {