@sitecore-content-sdk/react 2.4.0-canary.20260904084733 → 2.4.0-canary.20260907052454

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.
@@ -11,22 +11,42 @@ const SitecoreProvider_1 = require("./../components/SitecoreProvider");
11
11
  const DefaultEditingError = () => (react_1.default.createElement("div", { className: "sc-jss-editing-error", role: "alert" }, "Datasource is required. Please choose a content item for this component."));
12
12
  exports.DefaultEditingError = DefaultEditingError;
13
13
  /**
14
- * Checks whether a Sitecore datasource is present and renders appropriately depending on page mode (normal vs editing).
14
+ * Returns true when the rendering has a datasource and Layout Service did not report unresolved content.
15
+ * @param {ComponentRendering} [rendering] rendering data from Layout Service
16
+ * @returns {boolean} whether the datasource is present and valid
17
+ */
18
+ function hasValidDatasource(rendering) {
19
+ if (!(rendering === null || rendering === void 0 ? void 0 : rendering.dataSource)) {
20
+ return false;
21
+ }
22
+ return rendering.isContentResolved !== false;
23
+ }
24
+ /**
25
+ * Checks whether a Sitecore datasource is present and valid, then renders appropriately depending on page mode (normal vs editing).
26
+ * `isContentResolved: false` is treated the same as a missing datasource. If the property is omitted, the original presence check is used.
15
27
  * @param {WithDatasourceCheckOptions} [options]
16
28
  * @returns
17
- * The wrapped component, if a datasource is present.
18
- * A null component (in normal mode) or an error component (in editing mode), if a datasource is not present.
29
+ * The wrapped component, if a datasource is present and valid.
30
+ * A null component (in normal mode) or an error component (in editing mode), if a datasource is missing or failed to resolve.
31
+ * @example
32
+ * // Wrap once. Deleted/archived datasources (isContentResolved: false) use the same
33
+ * // fallback as a missing datasource: hide in normal mode, show an editing error in editing mode.
34
+ * const ContentBlock = (props) => <div>{props.fields.heading}</div>;
35
+ * export default withDatasourceCheck()(ContentBlock);
36
+ *
37
+ * // Layout Service: { componentName: 'ContentBlock', dataSource: '{id}', isContentResolved: false }
38
+ * // → ContentBlock is not rendered; no extra app-level check is required.
19
39
  * @public
20
40
  */
21
41
  function withDatasourceCheck(options) {
22
42
  return function withDatasourceCheckHoc(Component) {
23
43
  return (props) => {
24
- var _a, _b;
44
+ var _a;
25
45
  const { page } = (0, SitecoreProvider_1.useSitecore)();
26
46
  const EditingError = (_a = options === null || options === void 0 ? void 0 : options.editingErrorComponent) !== null && _a !== void 0 ? _a : exports.DefaultEditingError;
27
47
  // If the component is rendered in DesignLibrary, we don't need to check for datasource
28
48
  const isDesignLibrary = page.mode.isDesignLibrary;
29
- return isDesignLibrary || ((_b = props.rendering) === null || _b === void 0 ? void 0 : _b.dataSource) ? (react_1.default.createElement(Component, Object.assign({}, props))) : page.mode.isEditing ? (react_1.default.createElement(EditingError, null)) : null;
49
+ return isDesignLibrary || hasValidDatasource(props.rendering) ? (react_1.default.createElement(Component, Object.assign({}, props))) : page.mode.isEditing ? (react_1.default.createElement(EditingError, null)) : null;
30
50
  };
31
51
  };
32
52
  }
@@ -3,22 +3,42 @@ import React from 'react';
3
3
  import { useSitecore } from './../components/SitecoreProvider';
4
4
  export const DefaultEditingError = () => (React.createElement("div", { className: "sc-jss-editing-error", role: "alert" }, "Datasource is required. Please choose a content item for this component."));
5
5
  /**
6
- * Checks whether a Sitecore datasource is present and renders appropriately depending on page mode (normal vs editing).
6
+ * Returns true when the rendering has a datasource and Layout Service did not report unresolved content.
7
+ * @param {ComponentRendering} [rendering] rendering data from Layout Service
8
+ * @returns {boolean} whether the datasource is present and valid
9
+ */
10
+ function hasValidDatasource(rendering) {
11
+ if (!(rendering === null || rendering === void 0 ? void 0 : rendering.dataSource)) {
12
+ return false;
13
+ }
14
+ return rendering.isContentResolved !== false;
15
+ }
16
+ /**
17
+ * Checks whether a Sitecore datasource is present and valid, then renders appropriately depending on page mode (normal vs editing).
18
+ * `isContentResolved: false` is treated the same as a missing datasource. If the property is omitted, the original presence check is used.
7
19
  * @param {WithDatasourceCheckOptions} [options]
8
20
  * @returns
9
- * The wrapped component, if a datasource is present.
10
- * A null component (in normal mode) or an error component (in editing mode), if a datasource is not present.
21
+ * The wrapped component, if a datasource is present and valid.
22
+ * A null component (in normal mode) or an error component (in editing mode), if a datasource is missing or failed to resolve.
23
+ * @example
24
+ * // Wrap once. Deleted/archived datasources (isContentResolved: false) use the same
25
+ * // fallback as a missing datasource: hide in normal mode, show an editing error in editing mode.
26
+ * const ContentBlock = (props) => <div>{props.fields.heading}</div>;
27
+ * export default withDatasourceCheck()(ContentBlock);
28
+ *
29
+ * // Layout Service: { componentName: 'ContentBlock', dataSource: '{id}', isContentResolved: false }
30
+ * // → ContentBlock is not rendered; no extra app-level check is required.
11
31
  * @public
12
32
  */
13
33
  export function withDatasourceCheck(options) {
14
34
  return function withDatasourceCheckHoc(Component) {
15
35
  return (props) => {
16
- var _a, _b;
36
+ var _a;
17
37
  const { page } = useSitecore();
18
38
  const EditingError = (_a = options === null || options === void 0 ? void 0 : options.editingErrorComponent) !== null && _a !== void 0 ? _a : DefaultEditingError;
19
39
  // If the component is rendered in DesignLibrary, we don't need to check for datasource
20
40
  const isDesignLibrary = page.mode.isDesignLibrary;
21
- return isDesignLibrary || ((_b = props.rendering) === null || _b === void 0 ? void 0 : _b.dataSource) ? (React.createElement(Component, Object.assign({}, props))) : page.mode.isEditing ? (React.createElement(EditingError, null)) : null;
41
+ return isDesignLibrary || hasValidDatasource(props.rendering) ? (React.createElement(Component, Object.assign({}, props))) : page.mode.isEditing ? (React.createElement(EditingError, null)) : null;
22
42
  };
23
43
  };
24
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/react",
3
- "version": "2.4.0-canary.20260904084733",
3
+ "version": "2.4.0-canary.20260907052454",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -32,7 +32,7 @@
32
32
  "url": "https://github.com/sitecore/content-sdk/issues"
33
33
  },
34
34
  "devDependencies": {
35
- "@sitecore-content-sdk/analytics-core": "2.1.3-canary.20260904084733",
35
+ "@sitecore-content-sdk/analytics-core": "2.1.3-canary.20260907052454",
36
36
  "@sitecore-feaas/clientside": "^0.6.0",
37
37
  "@stylistic/eslint-plugin": "^5.2.2",
38
38
  "@testing-library/dom": "^10.4.0",
@@ -71,16 +71,16 @@
71
71
  "typescript": "~5.8.3"
72
72
  },
73
73
  "peerDependencies": {
74
- "@sitecore-content-sdk/analytics-core": "2.1.3-canary.20260904084733",
75
- "@sitecore-content-sdk/events": "2.1.3-canary.20260904084733",
74
+ "@sitecore-content-sdk/analytics-core": "2.1.3-canary.20260907052454",
75
+ "@sitecore-content-sdk/events": "2.1.3-canary.20260907052454",
76
76
  "@sitecore-feaas/clientside": "^0.6.0",
77
77
  "react": "^19.2.1",
78
78
  "react-dom": "^19.2.1"
79
79
  },
80
80
  "dependencies": {
81
- "@sitecore-content-sdk/content": "2.3.0-canary.20260904084733",
82
- "@sitecore-content-sdk/core": "2.1.4-canary.20260904084733",
83
- "@sitecore-content-sdk/search": "0.5.0-canary.20260904084733",
81
+ "@sitecore-content-sdk/content": "2.3.0-canary.20260907052454",
82
+ "@sitecore-content-sdk/core": "2.1.4-canary.20260907052454",
83
+ "@sitecore-content-sdk/search": "0.5.0-canary.20260907052454",
84
84
  "fast-deep-equal": "^3.1.3"
85
85
  },
86
86
  "description": "",
@@ -6,17 +6,26 @@ export interface WithDatasourceCheckProps {
6
6
  }
7
7
  export interface WithDatasourceCheckOptions {
8
8
  /**
9
- * A component that is rendered when a datasource is missing during editing.
9
+ * A component that is rendered when a datasource is missing or failed to resolve during editing.
10
10
  * If unspecified, a default component with message is displayed.
11
11
  */
12
12
  editingErrorComponent?: React.ComponentClass<unknown> | React.FC<unknown>;
13
13
  }
14
14
  /**
15
- * Checks whether a Sitecore datasource is present and renders appropriately depending on page mode (normal vs editing).
15
+ * Checks whether a Sitecore datasource is present and valid, then renders appropriately depending on page mode (normal vs editing).
16
+ * `isContentResolved: false` is treated the same as a missing datasource. If the property is omitted, the original presence check is used.
16
17
  * @param {WithDatasourceCheckOptions} [options]
17
18
  * @returns
18
- * The wrapped component, if a datasource is present.
19
- * A null component (in normal mode) or an error component (in editing mode), if a datasource is not present.
19
+ * The wrapped component, if a datasource is present and valid.
20
+ * A null component (in normal mode) or an error component (in editing mode), if a datasource is missing or failed to resolve.
21
+ * @example
22
+ * // Wrap once. Deleted/archived datasources (isContentResolved: false) use the same
23
+ * // fallback as a missing datasource: hide in normal mode, show an editing error in editing mode.
24
+ * const ContentBlock = (props) => <div>{props.fields.heading}</div>;
25
+ * export default withDatasourceCheck()(ContentBlock);
26
+ *
27
+ * // Layout Service: { componentName: 'ContentBlock', dataSource: '{id}', isContentResolved: false }
28
+ * // → ContentBlock is not rendered; no extra app-level check is required.
20
29
  * @public
21
30
  */
22
31
  export declare function withDatasourceCheck(options?: WithDatasourceCheckOptions): <ComponentProps extends WithDatasourceCheckProps>(Component: React.ComponentType<ComponentProps>) => (props: ComponentProps) => JSX.Element | null;
@@ -1 +1 @@
1
- {"version":3,"file":"withDatasourceCheck.d.ts","sourceRoot":"","sources":["../../src/enhancers/withDatasourceCheck.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAG1E,eAAO,MAAM,mBAAmB,QAAO,GAAG,CAAC,OAI1C,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,kBAAkB,CAAC;CAC/B;AAED,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,qBAAqB,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;CAC3E;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,0BAA0B,IAC/B,cAAc,SAAS,wBAAwB,EACpF,WAAW,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,MAEtC,OAAO,cAAc,wBAchC"}
1
+ {"version":3,"file":"withDatasourceCheck.d.ts","sourceRoot":"","sources":["../../src/enhancers/withDatasourceCheck.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAG1E,eAAO,MAAM,mBAAmB,QAAO,GAAG,CAAC,OAI1C,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,kBAAkB,CAAC;CAC/B;AAED,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,qBAAqB,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;CAC3E;AAeD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,0BAA0B,IAC/B,cAAc,SAAS,wBAAwB,EACpF,WAAW,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,MAEtC,OAAO,cAAc,wBAchC"}