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