@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.
@@ -2059,7 +2059,9 @@ function AmplifyRenderer({
2059
2059
  if (!pageConfig) {
2060
2060
  return;
2061
2061
  }
2062
- if (!pageConfig.layoutTree || Array.isArray(pageConfig.layoutTree) && pageConfig.layoutTree.length === 0) {
2062
+ const rawTree2 = pageConfig.layoutTree;
2063
+ const normalizedTree = Array.isArray(rawTree2) ? rawTree2 : rawTree2 && typeof rawTree2 === "object" && rawTree2.componentId ? [rawTree2] : [];
2064
+ if (normalizedTree.length === 0) {
2063
2065
  if (typeof window !== "undefined" && window.parent && window.parent !== window) {
2064
2066
  window.parent.postMessage({
2065
2067
  type: "COMPONENT_TREE",
@@ -2071,6 +2073,7 @@ function AmplifyRenderer({
2071
2073
  const convertLayoutTreeToComponentTree = (nodes, parentId = null) => {
2072
2074
  const result = [];
2073
2075
  nodes.forEach((node) => {
2076
+ if (!node) return;
2074
2077
  const treeNode = {
2075
2078
  id: node.id,
2076
2079
  componentId: node.componentId,
@@ -2081,8 +2084,9 @@ function AmplifyRenderer({
2081
2084
  };
2082
2085
  if (node.slots && node.slots.length > 0) {
2083
2086
  node.slots.forEach((slot) => {
2084
- if (slot.children && slot.children.length > 0) {
2085
- const slotChildren = convertLayoutTreeToComponentTree(slot.children, node.id);
2087
+ const kids = Array.isArray(slot?.children) ? slot.children : [];
2088
+ if (kids.length > 0) {
2089
+ const slotChildren = convertLayoutTreeToComponentTree(kids, node.id);
2086
2090
  treeNode.children.push(...slotChildren);
2087
2091
  }
2088
2092
  });
@@ -2091,7 +2095,7 @@ function AmplifyRenderer({
2091
2095
  });
2092
2096
  return result;
2093
2097
  };
2094
- const layoutTree2 = pageConfig.layoutTree;
2098
+ const layoutTree2 = normalizedTree;
2095
2099
  const componentTree = convertLayoutTreeToComponentTree(layoutTree2);
2096
2100
  const describeLayoutTree = (nodes, depth = 0) => {
2097
2101
  if (!nodes?.length) return "";
@@ -2264,11 +2268,12 @@ function AmplifyRenderer({
2264
2268
  childrenCount: childrenToRender.length
2265
2269
  });
2266
2270
  } else {
2267
- childrenToRender = slot.children;
2271
+ childrenToRender = Array.isArray(slot.children) ? slot.children : [];
2268
2272
  console.log(`[AmplifyRenderer] Using direct children for slot ${slot.slotId}`, {
2269
2273
  childrenCount: childrenToRender.length
2270
2274
  });
2271
2275
  }
2276
+ const safeChildren = Array.isArray(childrenToRender) ? childrenToRender : [];
2272
2277
  slotChildren[slot.slotId] = /* @__PURE__ */ jsx(
2273
2278
  "div",
2274
2279
  {
@@ -2277,7 +2282,7 @@ function AmplifyRenderer({
2277
2282
  "data-zone-id": slot.zoneId || void 0,
2278
2283
  "data-parent-node-id": node.id,
2279
2284
  "data-parent-component-id": node.componentId,
2280
- children: childrenToRender.map((child) => renderNode(child))
2285
+ children: safeChildren.filter(Boolean).map((child) => renderNode(child))
2281
2286
  },
2282
2287
  slot.slotId
2283
2288
  );