@amplifyup/sdk 0.1.54 → 0.1.56

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.
@@ -1,4 +1,4 @@
1
- import { i as AmplifyUpTarget } from './types-DpTzUg1C.js';
1
+ import { i as AmplifyUpTarget } from './types-Db_eLrfU.js';
2
2
 
3
3
  /**
4
4
  * On-request variant selection (tier 3).
@@ -1,4 +1,4 @@
1
- import { i as AmplifyUpTarget } from './types-DpTzUg1C.mjs';
1
+ import { i as AmplifyUpTarget } from './types-Db_eLrfU.mjs';
2
2
 
3
3
  /**
4
4
  * On-request variant selection (tier 3).
package/dist/react.d.mts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { P as PageConfig, c as AmplifyUpConfig, e as AmplifyPageContextInput, C as ContentSource, A as AmplifyContentMeta } from './types-DpTzUg1C.mjs';
3
- export { Z as ZoneConfig } from './types-DpTzUg1C.mjs';
4
- import React, { ReactNode } from 'react';
2
+ import { P as PageConfig, c as AmplifyUpConfig, e as AmplifyPageContextInput, C as ContentSource, A as AmplifyContentMeta } from './types-Db_eLrfU.mjs';
3
+ export { Z as ZoneConfig } from './types-Db_eLrfU.mjs';
4
+ import React__default, { ReactNode } from 'react';
5
5
  export { AmplifyRenderer } from './AmplifyRenderer.mjs';
6
- export { Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-CWFb7rSm.mjs';
6
+ export { Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-DaJlqU-Z.mjs';
7
7
  export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.mjs';
8
8
 
9
9
  type RenderComponentContext = {
@@ -90,14 +90,14 @@ declare function Field(props: {
90
90
  /** Field value from your component props. Do not also pass `name`. */
91
91
  value?: unknown;
92
92
  /**
93
- * @deprecated Will be removed. Use `value={…}` instead and omit `name`.
94
- * Do not pass `name` together with `value`.
93
+ * @deprecated Prefer `value={…}`. Still used as the Composer save key when
94
+ * the same value appears on more than one prop.
95
95
  */
96
96
  name?: string;
97
97
  fallback?: ReactNode;
98
98
  className?: string;
99
99
  render?: (value: any) => ReactNode;
100
- }): string | number | true | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null;
100
+ }): string | number | true | Iterable<React__default.ReactNode> | react_jsx_runtime.JSX.Element | null;
101
101
  /**
102
102
  * RichText - Renders a markdown (or HTML string) value as formatted HTML.
103
103
  *
@@ -120,8 +120,8 @@ declare function RichText(props: {
120
120
  /** Markdown (or HTML) string from your component props. Do not also pass `name`. */
121
121
  value?: string | null;
122
122
  /**
123
- * @deprecated Will be removed. Use `value={…}` (or string children) and omit `name`.
124
- * Do not pass `name` together with `value`.
123
+ * @deprecated Prefer `value={…}`. Still used as the Composer save key when
124
+ * the same value appears on more than one prop.
125
125
  */
126
126
  name?: string;
127
127
  fallback?: ReactNode;
@@ -154,7 +154,7 @@ declare function Image(props: {
154
154
  */
155
155
  name?: string;
156
156
  alt?: string;
157
- } & Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'src' | 'alt' | 'name'>): react_jsx_runtime.JSX.Element | null;
157
+ } & Omit<React__default.ImgHTMLAttributes<HTMLImageElement>, 'src' | 'alt' | 'name'>): react_jsx_runtime.JSX.Element | null;
158
158
 
159
159
  interface AmplifyUpContextType {
160
160
  pageConfig: PageConfig | null;
package/dist/react.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { P as PageConfig, c as AmplifyUpConfig, e as AmplifyPageContextInput, C as ContentSource, A as AmplifyContentMeta } from './types-DpTzUg1C.js';
3
- export { Z as ZoneConfig } from './types-DpTzUg1C.js';
4
- import React, { ReactNode } from 'react';
2
+ import { P as PageConfig, c as AmplifyUpConfig, e as AmplifyPageContextInput, C as ContentSource, A as AmplifyContentMeta } from './types-Db_eLrfU.js';
3
+ export { Z as ZoneConfig } from './types-Db_eLrfU.js';
4
+ import React__default, { ReactNode } from 'react';
5
5
  export { AmplifyRenderer } from './AmplifyRenderer.js';
6
- export { Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-L7zSmLFX.js';
6
+ export { Q as QueryContentError, e as QueryContentOptions, k as QueryFilter, l as QueryFilterOp, i as QueryPagination, h as QueryResult, m as QuerySort, j as QuerySpec, S as SelectVariantsError, a as SelectVariantsOptions, b as SelectVariantsResult, n as nextPageSpec, q as queryContent, d as searchSpec, s as selectVariants } from './query-BqApXxQi.js';
7
7
  export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.js';
8
8
 
9
9
  type RenderComponentContext = {
@@ -90,14 +90,14 @@ declare function Field(props: {
90
90
  /** Field value from your component props. Do not also pass `name`. */
91
91
  value?: unknown;
92
92
  /**
93
- * @deprecated Will be removed. Use `value={…}` instead and omit `name`.
94
- * Do not pass `name` together with `value`.
93
+ * @deprecated Prefer `value={…}`. Still used as the Composer save key when
94
+ * the same value appears on more than one prop.
95
95
  */
96
96
  name?: string;
97
97
  fallback?: ReactNode;
98
98
  className?: string;
99
99
  render?: (value: any) => ReactNode;
100
- }): string | number | true | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null;
100
+ }): string | number | true | Iterable<React__default.ReactNode> | react_jsx_runtime.JSX.Element | null;
101
101
  /**
102
102
  * RichText - Renders a markdown (or HTML string) value as formatted HTML.
103
103
  *
@@ -120,8 +120,8 @@ declare function RichText(props: {
120
120
  /** Markdown (or HTML) string from your component props. Do not also pass `name`. */
121
121
  value?: string | null;
122
122
  /**
123
- * @deprecated Will be removed. Use `value={…}` (or string children) and omit `name`.
124
- * Do not pass `name` together with `value`.
123
+ * @deprecated Prefer `value={…}`. Still used as the Composer save key when
124
+ * the same value appears on more than one prop.
125
125
  */
126
126
  name?: string;
127
127
  fallback?: ReactNode;
@@ -154,7 +154,7 @@ declare function Image(props: {
154
154
  */
155
155
  name?: string;
156
156
  alt?: string;
157
- } & Omit<React.ImgHTMLAttributes<HTMLImageElement>, 'src' | 'alt' | 'name'>): react_jsx_runtime.JSX.Element | null;
157
+ } & Omit<React__default.ImgHTMLAttributes<HTMLImageElement>, 'src' | 'alt' | 'name'>): react_jsx_runtime.JSX.Element | null;
158
158
 
159
159
  interface AmplifyUpContextType {
160
160
  pageConfig: PageConfig | null;
package/dist/react.js CHANGED
@@ -614,6 +614,49 @@ function getPageResourceFields() {
614
614
  return pageResourceFields;
615
615
  }
616
616
 
617
+ // src/debug.ts
618
+ function envFlag(value) {
619
+ if (!value) return false;
620
+ const v = value.trim().toLowerCase();
621
+ return v === "1" || v === "true" || v === "yes";
622
+ }
623
+ function readAmplifyUpDebugEnv() {
624
+ try {
625
+ if (typeof process === "undefined") return false;
626
+ return envFlag(process.env.NEXT_PUBLIC_AMPLIFYUP_DEBUG) || envFlag(process.env.AMPLIFYUP_DEBUG);
627
+ } catch {
628
+ return false;
629
+ }
630
+ }
631
+ var configDebug;
632
+ function setAmplifyUpDebug(enabled) {
633
+ configDebug = enabled;
634
+ }
635
+ function isAmplifyUpDebug() {
636
+ if (configDebug === true) return true;
637
+ if (configDebug === false) return false;
638
+ return readAmplifyUpDebugEnv();
639
+ }
640
+ var onceKeys = /* @__PURE__ */ new Set();
641
+ var onceRoute = "";
642
+ function resetOnceIfRouteChanged() {
643
+ const route = typeof window !== "undefined" ? window.location.pathname : "";
644
+ if (route === onceRoute) return;
645
+ onceKeys.clear();
646
+ onceRoute = route;
647
+ }
648
+ function sdkDebug(...args) {
649
+ if (!isAmplifyUpDebug()) return;
650
+ console.log(...args);
651
+ }
652
+ function sdkDebugOnce(key, ...args) {
653
+ if (!isAmplifyUpDebug()) return;
654
+ resetOnceIfRouteChanged();
655
+ if (onceKeys.has(key)) return;
656
+ onceKeys.add(key);
657
+ console.log(...args);
658
+ }
659
+
617
660
  // src/edge/normalizeRoute.ts
618
661
  function normalizeRoute(route) {
619
662
  let path = String(route || "").trim();
@@ -1187,13 +1230,13 @@ var AmplifyUpSDK = class {
1187
1230
  }
1188
1231
  this.config = {
1189
1232
  trackingId: previewOverrides.trackingId || config.trackingId,
1190
- debug: config.debug ?? true,
1191
- // Enable debug by default
1233
+ debug: config.debug ?? readAmplifyUpDebugEnv(),
1192
1234
  target: this.target,
1193
1235
  dev: config.dev,
1194
1236
  ...config.siteId ? { siteId: config.siteId } : {},
1195
1237
  ...config.pageContext ? { pageContext: config.pageContext } : {}
1196
1238
  };
1239
+ setAmplifyUpDebug(!!this.config.debug);
1197
1240
  if (config.pageContext) {
1198
1241
  this.pendingPageContext = config.pageContext;
1199
1242
  this.recomputeAttachedContext();
@@ -3525,23 +3568,12 @@ function Slot({
3525
3568
  className
3526
3569
  }) {
3527
3570
  const context = React.useContext(ComponentContext);
3528
- console.log(`[Slot:${name}] Rendering slot`, {
3529
- hasContext: !!context,
3530
- availableSlotKeys: context?.slots ? Object.keys(context.slots) : [],
3531
- slotContent: context?.slots?.[name] ? "EXISTS" : "MISSING",
3532
- contextSlots: context?.slots
3533
- });
3534
3571
  if (!context) {
3535
3572
  console.warn(`[AmplifyUp SDK] Slot "${name}" used outside ComponentContextProvider`);
3536
3573
  return null;
3537
3574
  }
3538
3575
  const slotContent = context.slots?.[name];
3539
3576
  const isEmpty = !slotContent;
3540
- console.log(`[Slot:${name}] Slot state`, {
3541
- isEmpty,
3542
- hasSlotContent: !!slotContent,
3543
- slotContentType: slotContent ? typeof slotContent : "null"
3544
- });
3545
3577
  const isEditorMode = typeof window !== "undefined" && // Check for preview mode flag set by proxy
3546
3578
  (window.__AMPLIFYUP_PREVIEW_MODE__ === true || // Check URL query params
3547
3579
  new URLSearchParams(window.location.search).get("preview") === "true" || new URLSearchParams(window.location.search).get("visualEditor") === "true" || // Check if in iframe from orchestrator (check referrer hostname/port)
@@ -3553,17 +3585,15 @@ function Slot({
3553
3585
  return false;
3554
3586
  }
3555
3587
  })());
3556
- console.log(`[Slot:${name}] Editor mode detection`, {
3557
- isEditorMode,
3558
- isWindowDefined: typeof window !== "undefined",
3559
- previewModeFlag: typeof window !== "undefined" ? window.__AMPLIFYUP_PREVIEW_MODE__ : void 0,
3560
- urlParams: typeof window !== "undefined" ? {
3561
- preview: new URLSearchParams(window.location.search).get("preview"),
3562
- visualEditor: new URLSearchParams(window.location.search).get("visualEditor")
3563
- } : void 0,
3564
- inIframe: typeof window !== "undefined" ? window.self !== window.top : false,
3565
- referrer: typeof window !== "undefined" && document.referrer ? document.referrer : void 0
3566
- });
3588
+ sdkDebugOnce(
3589
+ `slot:${context.layoutNodeId || ""}:${name}`,
3590
+ `[Slot:${name}]`,
3591
+ {
3592
+ isEmpty,
3593
+ isEditorMode,
3594
+ availableSlotKeys: context.slots ? Object.keys(context.slots) : []
3595
+ }
3596
+ );
3567
3597
  return /* @__PURE__ */ jsxRuntime.jsx(
3568
3598
  "div",
3569
3599
  {
@@ -3655,13 +3685,31 @@ function htmlHasVisualChrome(html) {
3655
3685
  );
3656
3686
  }
3657
3687
  function canInlineEdit(name, value) {
3658
- if (isLikelyNonTextFieldName(name)) return false;
3688
+ if (!name || isLikelyNonTextFieldName(name)) return false;
3659
3689
  if (value !== void 0 && value !== null && typeof value === "object") {
3660
3690
  return false;
3661
3691
  }
3662
3692
  if (typeof value === "boolean") return false;
3663
3693
  return true;
3664
3694
  }
3695
+ function canInlineEditRichText(name, value) {
3696
+ if (!name || isLikelyNonTextFieldName(name)) return false;
3697
+ if (typeof value === "boolean") return false;
3698
+ if (value !== void 0 && value !== null && typeof value === "object" && !Array.isArray(value)) {
3699
+ return false;
3700
+ }
3701
+ return true;
3702
+ }
3703
+ function inferEditName(explicitName, contextProps, sourceValue) {
3704
+ if (explicitName) return explicitName;
3705
+ if (!contextProps) return "";
3706
+ const keys = Object.keys(contextProps).filter(
3707
+ (key) => Object.is(contextProps[key], sourceValue)
3708
+ );
3709
+ if (keys.length === 1) return keys[0];
3710
+ if (keys.length === 0 || isComposerEmptyText(sourceValue)) return "";
3711
+ return keys[0];
3712
+ }
3665
3713
  function subscribeComposerEdit(onStoreChange) {
3666
3714
  if (typeof window === "undefined") return () => {
3667
3715
  };
@@ -3856,9 +3904,11 @@ function ComposerInlineHtml({
3856
3904
  const finishEdit = () => {
3857
3905
  const el = elRef.current;
3858
3906
  if (!el) return;
3859
- const next = (el.innerText ?? "").replace(/\u00a0/g, " ").replace(/\n+$/g, "");
3860
- if (next.trim() === sourceTextRef.current) return;
3861
- commitComposerField(layoutNodeId, componentId, name, next.trim());
3907
+ const nextHtml = el.innerHTML;
3908
+ const nextText = (el.innerText ?? "").replace(/\u00a0/g, " ").replace(/\n+$/g, "").trim();
3909
+ if (nextText === sourceTextRef.current && nextHtml === html) return;
3910
+ const commitValue = htmlHasVisualChrome(html) || /<[a-z][\s\S]*>/i.test(html) ? nextHtml : nextText;
3911
+ commitComposerField(layoutNodeId, componentId, name, commitValue);
3862
3912
  };
3863
3913
  return React__default.default.createElement(Tag, {
3864
3914
  ref: elRef,
@@ -3900,15 +3950,10 @@ function formatFieldValue(value) {
3900
3950
  }
3901
3951
  function warnProjectionProps(component, name, hasExplicitValue) {
3902
3952
  if (process.env.NODE_ENV === "production") return;
3903
- if (hasExplicitValue && name) {
3904
- console.warn(
3905
- `[AmplifyUp SDK] ${component}: pass either value={\u2026} or deprecated name="\u2026", not both. Prefer value={\u2026} and omit name.`
3906
- );
3907
- return;
3908
- }
3953
+ if (hasExplicitValue) return;
3909
3954
  if (name) {
3910
3955
  console.warn(
3911
- `[AmplifyUp SDK] ${component} \`name\` is deprecated and will be removed. Prefer value={${name}} from your component props and omit name.`
3956
+ `[AmplifyUp SDK] ${component} \`name\` is deprecated and will be removed. Prefer value={${name}} from your component props.`
3912
3957
  );
3913
3958
  }
3914
3959
  }
@@ -3948,7 +3993,7 @@ function Field(props) {
3948
3993
  const composerEdit = useComposerEditMode();
3949
3994
  const hasExplicitValue = hasOwnProp(props, "value");
3950
3995
  const sourceValue = hasExplicitValue ? value : name ? context?.props?.[name] : void 0;
3951
- const editName = hasExplicitValue ? "" : name || "";
3996
+ const editName = inferEditName(name, context?.props, sourceValue);
3952
3997
  const fieldValue = useFieldOverlay(
3953
3998
  context?.layoutNodeId,
3954
3999
  editName,
@@ -3962,6 +4007,20 @@ function Field(props) {
3962
4007
  return fallback ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
3963
4008
  }
3964
4009
  if (render) {
4010
+ if (composerEdit && editName && context && canInlineEdit(editName, fieldValue)) {
4011
+ return /* @__PURE__ */ jsxRuntime.jsx(
4012
+ ComposerInlineField,
4013
+ {
4014
+ name: editName,
4015
+ value: fieldValue,
4016
+ fallback,
4017
+ className,
4018
+ render,
4019
+ layoutNodeId: context.layoutNodeId,
4020
+ componentId: context.componentId
4021
+ }
4022
+ );
4023
+ }
3965
4024
  return /* @__PURE__ */ jsxRuntime.jsx("span", { className, style: { display: "contents" }, children: render(fieldValue) });
3966
4025
  }
3967
4026
  if (Array.isArray(fieldValue)) {
@@ -4015,7 +4074,7 @@ function RichText(props) {
4015
4074
  const hasValueProp = hasOwnProp(props, "value");
4016
4075
  const hasExplicitValue = hasValueProp || childrenValue !== void 0;
4017
4076
  const sourceValue = hasValueProp ? value : childrenValue !== void 0 ? childrenValue : name ? context?.props?.[name] : void 0;
4018
- const editName = hasExplicitValue ? "" : name || "";
4077
+ const editName = inferEditName(name, context?.props, sourceValue);
4019
4078
  const fieldValue = useFieldOverlay(
4020
4079
  context?.layoutNodeId,
4021
4080
  editName,
@@ -4028,7 +4087,7 @@ function RichText(props) {
4028
4087
  return fallback ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
4029
4088
  }
4030
4089
  warnProjectionProps("RichText", name, hasExplicitValue);
4031
- const canEdit = !!editName && !!context && canInlineEdit(editName, fieldValue);
4090
+ const canEdit = !!context && canInlineEditRichText(editName, fieldValue);
4032
4091
  if (isComposerEmptyText(fieldValue)) {
4033
4092
  if (composerEdit && canEdit && !isReactNodeFallback(fallback) && !classNameIsBlock(className)) {
4034
4093
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -4060,17 +4119,6 @@ function RichText(props) {
4060
4119
  if (!html) {
4061
4120
  return fallback ? /* @__PURE__ */ jsxRuntime.jsx(Tag, { className, children: fallback }) : null;
4062
4121
  }
4063
- if (composerEdit && htmlHasVisualChrome(html)) {
4064
- return /* @__PURE__ */ jsxRuntime.jsx(
4065
- Tag,
4066
- {
4067
- className,
4068
- "data-amplifyup-field": editName || void 0,
4069
- "data-amplifyup-node-id": context?.layoutNodeId || void 0,
4070
- dangerouslySetInnerHTML: { __html: html }
4071
- }
4072
- );
4073
- }
4074
4122
  if (composerEdit && canEdit) {
4075
4123
  return /* @__PURE__ */ jsxRuntime.jsx(
4076
4124
  ComposerInlineHtml,
@@ -4111,7 +4159,7 @@ function Image(props) {
4111
4159
  const sourceValue = hasExplicitValue ? value : name ? context?.props?.[name] : void 0;
4112
4160
  const fieldValue = useFieldOverlay(
4113
4161
  context?.layoutNodeId,
4114
- hasExplicitValue ? "" : name || "",
4162
+ inferEditName(name, context?.props, sourceValue),
4115
4163
  sourceValue
4116
4164
  );
4117
4165
  warnProjectionProps("Image", name, hasExplicitValue);
@@ -4204,7 +4252,7 @@ function LiveNodeRender({
4204
4252
  layoutNodeId: nodeId
4205
4253
  }) });
4206
4254
  }
4207
- function AmplifyRenderer({
4255
+ function AmplifyRendererInner({
4208
4256
  renderComponent,
4209
4257
  pageConfig: serverPageConfig,
4210
4258
  loadingComponent,
@@ -4346,14 +4394,22 @@ function AmplifyRenderer({
4346
4394
  return `${indent}- ${n.id} (${n.componentId || "?"})${slotsDesc ? "\n" + slotsDesc : ""}`;
4347
4395
  }).join("\n");
4348
4396
  };
4349
- console.log("[AmplifyRenderer] layoutTree received:\n%s", describeLayoutTree(layoutTree2));
4397
+ sdkDebugOnce(
4398
+ `layoutTree:${pageConfig?.id || ""}:${pageConfig?.route || ""}`,
4399
+ "[AmplifyRenderer] layoutTree received:\n%s",
4400
+ describeLayoutTree(layoutTree2)
4401
+ );
4350
4402
  if (typeof window !== "undefined" && window.parent && window.parent !== window) {
4351
4403
  const message = {
4352
4404
  type: "COMPONENT_TREE",
4353
4405
  tree: componentTree
4354
4406
  };
4355
4407
  window.parent.postMessage(message, "*");
4356
- console.log("[AmplifyRenderer] Sent component tree from layoutTree:", componentTree.length, "root components");
4408
+ sdkDebug(
4409
+ "[AmplifyRenderer] Sent component tree from layoutTree:",
4410
+ componentTree.length,
4411
+ "root components"
4412
+ );
4357
4413
  }
4358
4414
  }, [pageConfig]);
4359
4415
  React.useEffect(() => {
@@ -4504,7 +4560,7 @@ function AmplifyRenderer({
4504
4560
  );
4505
4561
  }
4506
4562
  let slotChildren = {};
4507
- console.log(`[AmplifyRenderer] Rendering node ${node.id} (${node.componentId})`, {
4563
+ sdkDebugOnce(`node:${node.id}`, `[AmplifyRenderer] Rendering node ${node.id} (${node.componentId})`, {
4508
4564
  hasSlots: !!(node.slots && node.slots.length > 0),
4509
4565
  slotCount: node.slots?.length || 0,
4510
4566
  slots: node.slots?.map((s) => ({ slotId: s.slotId, zoneId: s.zoneId, childrenCount: s.children?.length || 0 }))
@@ -4513,30 +4569,13 @@ function AmplifyRenderer({
4513
4569
  for (const slot of node.slots) {
4514
4570
  const slotKey = `${node.id}-${slot.slotId}`;
4515
4571
  let childrenToRender = [];
4516
- console.log(`[AmplifyRenderer] Processing slot ${slot.slotId} for node ${node.id}`, {
4517
- slotKey,
4518
- hasZoneId: !!slot.zoneId,
4519
- hasVariants: !!slot.variants,
4520
- hasVariantCache: !!variantCache[slotKey],
4521
- directChildrenCount: slot.children?.length || 0
4522
- });
4523
4572
  if (slot.zoneId && slot.variants && variantCache[slotKey]) {
4524
4573
  childrenToRender = variantCache[slotKey].children;
4525
- console.log(`[AmplifyRenderer] Using cached variant for slot ${slot.slotId}`, {
4526
- variantId: variantCache[slotKey].variantId,
4527
- childrenCount: childrenToRender.length
4528
- });
4529
4574
  } else if (slot.zoneId && slot.variants) {
4530
4575
  const defaultVariant = slot.variants.find((v) => v.isDefault);
4531
4576
  childrenToRender = defaultVariant?.children || [];
4532
- console.log(`[AmplifyRenderer] Using default variant for slot ${slot.slotId}`, {
4533
- childrenCount: childrenToRender.length
4534
- });
4535
4577
  } else {
4536
4578
  childrenToRender = Array.isArray(slot.children) ? slot.children : [];
4537
- console.log(`[AmplifyRenderer] Using direct children for slot ${slot.slotId}`, {
4538
- childrenCount: childrenToRender.length
4539
- });
4540
4579
  }
4541
4580
  const safeChildren = Array.isArray(childrenToRender) ? childrenToRender : [];
4542
4581
  slotChildren[slot.slotId] = /* @__PURE__ */ jsxRuntime.jsx(
@@ -4551,10 +4590,6 @@ function AmplifyRenderer({
4551
4590
  },
4552
4591
  slot.slotId
4553
4592
  );
4554
- console.log(`[AmplifyRenderer] Created slot content for ${slot.slotId}`, {
4555
- slotId: slot.slotId,
4556
- renderedChildrenCount: childrenToRender.length
4557
- });
4558
4593
  }
4559
4594
  }
4560
4595
  const slotsToPass = Object.keys(slotChildren).length > 0 ? slotChildren : void 0;
@@ -4592,6 +4627,7 @@ function AmplifyRenderer({
4592
4627
  }
4593
4628
  ) : layoutTree.map((node) => /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderNode(node) }, node.id)) });
4594
4629
  }
4630
+ var AmplifyRenderer = React.memo(AmplifyRendererInner);
4595
4631
  function defaultPreviewCanvas() {
4596
4632
  return /* @__PURE__ */ jsxRuntime.jsx(
4597
4633
  "div",
@@ -4695,6 +4731,12 @@ if (typeof window !== "undefined") {
4695
4731
  }
4696
4732
  }
4697
4733
  var AmplifyUpContext = React.createContext(null);
4734
+ function normalizeRoutePath2(route) {
4735
+ if (!route) return "";
4736
+ const path = route.split("?")[0] || "/";
4737
+ if (path.length > 1 && path.endsWith("/")) return path.replace(/\/+$/, "");
4738
+ return path || "/";
4739
+ }
4698
4740
  function AmplifyUpProvider({
4699
4741
  children,
4700
4742
  config,
@@ -4722,6 +4764,7 @@ function AmplifyUpProvider({
4722
4764
  }
4723
4765
  return currentPath;
4724
4766
  };
4767
+ const loadedRouteRef = React.useRef(null);
4725
4768
  const nextPathname = usePathname ? usePathname() : null;
4726
4769
  const [pathname, setPathname] = React.useState(() => {
4727
4770
  if (typeof window !== "undefined") {
@@ -4755,56 +4798,46 @@ function AmplifyUpProvider({
4755
4798
  };
4756
4799
  }
4757
4800
  }, [nextPathname]);
4758
- React.useEffect(() => {
4759
- let cancelled = false;
4760
- const sdk = getSDK();
4761
- sdk.init({
4762
- ...config,
4763
- ...pageContext ? { pageContext } : {}
4764
- }).then(() => {
4765
- if (!cancelled) {
4766
- setInitialized(true);
4767
- }
4768
- }).catch((err) => {
4769
- if (cancelled) return;
4770
- console.error("Failed to initialize AmplifyUp SDK:", err);
4771
- setError("Failed to initialize tracking");
4772
- setLoading(false);
4773
- });
4774
- return () => {
4775
- cancelled = true;
4776
- };
4777
- }, [config.trackingId, config.target, config.debug, config.dev, config.siteId, pageContext]);
4801
+ const pageContextKey = pageContext ? `${pageContext.resourceType}:${pageContext.key}` : "";
4778
4802
  React.useEffect(() => {
4779
4803
  if (!initialized || !pageContext) return;
4780
4804
  getSDK().setPageContext(pageContext);
4781
- }, [initialized, pageContext]);
4805
+ }, [initialized, pageContextKey]);
4782
4806
  React.useEffect(() => {
4783
- if (!initialized) return;
4784
4807
  let cancelled = false;
4785
- const load = async () => {
4808
+ const sdk = getSDK();
4809
+ const run = async () => {
4786
4810
  try {
4811
+ await sdk.init({
4812
+ ...config,
4813
+ ...pageContext ? { pageContext } : {}
4814
+ });
4815
+ if (cancelled) return;
4816
+ if (pageContext) sdk.setPageContext(pageContext);
4787
4817
  const actualRoute = getActualRoute();
4788
4818
  if (!actualRoute) {
4819
+ setInitialized(true);
4789
4820
  setLoading(false);
4790
4821
  return;
4791
4822
  }
4792
- const sdk = getSDK();
4793
4823
  sdk.routeChange(actualRoute);
4794
4824
  const preview = isComposerPreview();
4795
4825
  const overlay = preview || config.clientPersonalization !== false;
4796
4826
  if (!overlay) {
4827
+ setInitialized(true);
4797
4828
  setPageConfig(null);
4798
4829
  setLoading(false);
4799
4830
  return;
4800
4831
  }
4801
- setPageConfig(null);
4802
- setError(null);
4803
- setLoading(false);
4832
+ if (loadedRouteRef.current && loadedRouteRef.current !== actualRoute) {
4833
+ setPageConfig(null);
4834
+ setError(null);
4835
+ }
4804
4836
  const edgeUrl = sdk.getEdgeUrl();
4805
4837
  const orchestratorUrl = sdk.getOrchestratorUrl();
4806
4838
  const trackingId = sdk.getTrackingId();
4807
4839
  if (!trackingId || !orchestratorUrl || !edgeUrl) {
4840
+ setInitialized(true);
4808
4841
  setError("SDK not initialized");
4809
4842
  setLoading(false);
4810
4843
  return;
@@ -4840,28 +4873,37 @@ function AmplifyUpProvider({
4840
4873
  fetchOrchestratorPage: (route, isPreview) => sdk.fetchPageConfig(route, isPreview)
4841
4874
  });
4842
4875
  if (cancelled) return;
4843
- setSource(result.source);
4844
- setMeta(result.meta);
4845
- setError(result.error);
4846
- if (!result.pageConfig) {
4847
- setPageConfig({
4848
- id: "default",
4849
- route: actualRoute,
4850
- title: "Page Not Configured",
4851
- description: "This page has not been published yet.",
4852
- layoutTree: []
4853
- });
4854
- } else {
4855
- setPageConfig(result.pageConfig);
4876
+ const nextConfig = result.pageConfig || {
4877
+ id: "default",
4878
+ route: actualRoute,
4879
+ title: "Page Not Configured",
4880
+ description: "This page has not been published yet.",
4881
+ layoutTree: []
4882
+ };
4883
+ setInitialized(true);
4884
+ setSource((prev) => prev === result.source ? prev : result.source);
4885
+ setMeta(
4886
+ (prev) => prev === result.meta || JSON.stringify(prev) === JSON.stringify(result.meta) ? prev : result.meta
4887
+ );
4888
+ setError((prev) => prev === result.error ? prev : result.error);
4889
+ setPageConfig((prev) => {
4890
+ if (prev && prev.id === nextConfig.id && normalizeRoutePath2(prev.route) === normalizeRoutePath2(nextConfig.route) && JSON.stringify(prev.layoutTree) === JSON.stringify(nextConfig.layoutTree)) {
4891
+ return prev;
4892
+ }
4893
+ return nextConfig;
4894
+ });
4895
+ if (result.pageConfig) {
4856
4896
  sdk.applyResolvedPageData(
4857
4897
  result.pageConfig.pageData || null,
4858
4898
  result.pageConfig.route,
4859
4899
  extractRouteParams(result.pageConfig.route, actualRoute)
4860
4900
  );
4861
4901
  }
4902
+ loadedRouteRef.current = actualRoute;
4862
4903
  } catch (err) {
4863
4904
  if (cancelled) return;
4864
4905
  console.error("Error fetching page config:", err);
4906
+ setInitialized(true);
4865
4907
  setError(err instanceof Error ? err.message : "Unknown error");
4866
4908
  setSource(null);
4867
4909
  setMeta(null);
@@ -4869,11 +4911,20 @@ function AmplifyUpProvider({
4869
4911
  if (!cancelled) setLoading(false);
4870
4912
  }
4871
4913
  };
4872
- void load();
4914
+ void run();
4873
4915
  return () => {
4874
4916
  cancelled = true;
4875
4917
  };
4876
- }, [pathname, initialized, config.clientPersonalization]);
4918
+ }, [
4919
+ pathname,
4920
+ config.trackingId,
4921
+ config.target,
4922
+ config.debug,
4923
+ config.dev,
4924
+ config.siteId,
4925
+ config.clientPersonalization,
4926
+ pageContextKey
4927
+ ]);
4877
4928
  return /* @__PURE__ */ jsxRuntime.jsx(
4878
4929
  AmplifyUpContext.Provider,
4879
4930
  {