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