@amplifyup/sdk 0.1.13 → 0.1.14

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/dist/react.js CHANGED
@@ -2042,7 +2042,9 @@ function AmplifyRenderer({
2042
2042
  if (!pageConfig) {
2043
2043
  return;
2044
2044
  }
2045
- if (!pageConfig.layoutTree || Array.isArray(pageConfig.layoutTree) && pageConfig.layoutTree.length === 0) {
2045
+ const rawTree2 = pageConfig.layoutTree;
2046
+ const normalizedTree = Array.isArray(rawTree2) ? rawTree2 : rawTree2 && typeof rawTree2 === "object" && rawTree2.componentId ? [rawTree2] : [];
2047
+ if (normalizedTree.length === 0) {
2046
2048
  if (typeof window !== "undefined" && window.parent && window.parent !== window) {
2047
2049
  window.parent.postMessage({
2048
2050
  type: "COMPONENT_TREE",
@@ -2054,6 +2056,7 @@ function AmplifyRenderer({
2054
2056
  const convertLayoutTreeToComponentTree = (nodes, parentId = null) => {
2055
2057
  const result = [];
2056
2058
  nodes.forEach((node) => {
2059
+ if (!node) return;
2057
2060
  const treeNode = {
2058
2061
  id: node.id,
2059
2062
  componentId: node.componentId,
@@ -2064,8 +2067,9 @@ function AmplifyRenderer({
2064
2067
  };
2065
2068
  if (node.slots && node.slots.length > 0) {
2066
2069
  node.slots.forEach((slot) => {
2067
- if (slot.children && slot.children.length > 0) {
2068
- const slotChildren = convertLayoutTreeToComponentTree(slot.children, node.id);
2070
+ const kids = Array.isArray(slot?.children) ? slot.children : [];
2071
+ if (kids.length > 0) {
2072
+ const slotChildren = convertLayoutTreeToComponentTree(kids, node.id);
2069
2073
  treeNode.children.push(...slotChildren);
2070
2074
  }
2071
2075
  });
@@ -2074,7 +2078,7 @@ function AmplifyRenderer({
2074
2078
  });
2075
2079
  return result;
2076
2080
  };
2077
- const layoutTree2 = pageConfig.layoutTree;
2081
+ const layoutTree2 = normalizedTree;
2078
2082
  const componentTree = convertLayoutTreeToComponentTree(layoutTree2);
2079
2083
  const describeLayoutTree = (nodes, depth = 0) => {
2080
2084
  if (!nodes?.length) return "";
@@ -2247,11 +2251,12 @@ function AmplifyRenderer({
2247
2251
  childrenCount: childrenToRender.length
2248
2252
  });
2249
2253
  } else {
2250
- childrenToRender = slot.children;
2254
+ childrenToRender = Array.isArray(slot.children) ? slot.children : [];
2251
2255
  console.log(`[AmplifyRenderer] Using direct children for slot ${slot.slotId}`, {
2252
2256
  childrenCount: childrenToRender.length
2253
2257
  });
2254
2258
  }
2259
+ const safeChildren = Array.isArray(childrenToRender) ? childrenToRender : [];
2255
2260
  slotChildren[slot.slotId] = /* @__PURE__ */ jsxRuntime.jsx(
2256
2261
  "div",
2257
2262
  {
@@ -2260,7 +2265,7 @@ function AmplifyRenderer({
2260
2265
  "data-zone-id": slot.zoneId || void 0,
2261
2266
  "data-parent-node-id": node.id,
2262
2267
  "data-parent-component-id": node.componentId,
2263
- children: childrenToRender.map((child) => renderNode(child))
2268
+ children: safeChildren.filter(Boolean).map((child) => renderNode(child))
2264
2269
  },
2265
2270
  slot.slotId
2266
2271
  );