@amplifyup/sdk 0.1.53 → 0.1.55
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/AmplifyRenderer.d.mts +5 -3
- package/dist/AmplifyRenderer.d.ts +5 -3
- package/dist/AmplifyRenderer.js +64 -35
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +65 -36
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{query-L7zSmLFX.d.ts → query-BqApXxQi.d.ts} +1 -1
- package/dist/{query-CWFb7rSm.d.mts → query-DaJlqU-Z.d.mts} +1 -1
- package/dist/react.d.mts +6 -6
- package/dist/react.d.ts +6 -6
- package/dist/react.js +132 -100
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +134 -102
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +3 -3
- package/dist/server.d.ts +3 -3
- package/dist/{types-DpTzUg1C.d.mts → types-Db_eLrfU.d.mts} +5 -0
- package/dist/{types-DpTzUg1C.d.ts → types-Db_eLrfU.d.ts} +5 -0
- package/package.json +1 -1
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-
|
|
3
|
-
export { Z as ZoneConfig } from './types-
|
|
4
|
-
import
|
|
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-
|
|
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 = {
|
|
@@ -97,7 +97,7 @@ declare function Field(props: {
|
|
|
97
97
|
fallback?: ReactNode;
|
|
98
98
|
className?: string;
|
|
99
99
|
render?: (value: any) => ReactNode;
|
|
100
|
-
}): string | number | true | react_jsx_runtime.JSX.Element |
|
|
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
|
*
|
|
@@ -154,7 +154,7 @@ declare function Image(props: {
|
|
|
154
154
|
*/
|
|
155
155
|
name?: string;
|
|
156
156
|
alt?: string;
|
|
157
|
-
} & Omit<
|
|
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-
|
|
3
|
-
export { Z as ZoneConfig } from './types-
|
|
4
|
-
import
|
|
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-
|
|
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 = {
|
|
@@ -97,7 +97,7 @@ declare function Field(props: {
|
|
|
97
97
|
fallback?: ReactNode;
|
|
98
98
|
className?: string;
|
|
99
99
|
render?: (value: any) => ReactNode;
|
|
100
|
-
}): string | number | true | react_jsx_runtime.JSX.Element |
|
|
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
|
*
|
|
@@ -154,7 +154,7 @@ declare function Image(props: {
|
|
|
154
154
|
*/
|
|
155
155
|
name?: string;
|
|
156
156
|
alt?: string;
|
|
157
|
-
} & Omit<
|
|
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 ??
|
|
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();
|
|
@@ -3440,11 +3483,9 @@ function EmptySlotHint({
|
|
|
3440
3483
|
}
|
|
3441
3484
|
var ComponentContext = React.createContext(null);
|
|
3442
3485
|
function useLiveComposerProps(layoutNodeId, props) {
|
|
3443
|
-
const [
|
|
3444
|
-
React.useEffect(() => {
|
|
3445
|
-
setLive(props);
|
|
3446
|
-
}, [props]);
|
|
3486
|
+
const [patch, setPatch] = React.useState(null);
|
|
3447
3487
|
React.useEffect(() => {
|
|
3488
|
+
setPatch(null);
|
|
3448
3489
|
const matchesNode = (nodeId) => {
|
|
3449
3490
|
if (nodeId && layoutNodeId && String(nodeId) !== String(layoutNodeId)) {
|
|
3450
3491
|
return false;
|
|
@@ -3454,15 +3495,15 @@ function useLiveComposerProps(layoutNodeId, props) {
|
|
|
3454
3495
|
const applyField = (fieldName, value, nodeId) => {
|
|
3455
3496
|
if (!fieldName || typeof fieldName !== "string") return;
|
|
3456
3497
|
if (!matchesNode(nodeId)) return;
|
|
3457
|
-
|
|
3498
|
+
setPatch((prev) => ({ ...prev || {}, [fieldName]: value }));
|
|
3458
3499
|
};
|
|
3459
3500
|
const applyProps = (nextProps, nodeId) => {
|
|
3460
3501
|
if (!nextProps || typeof nextProps !== "object" || Array.isArray(nextProps)) {
|
|
3461
3502
|
return;
|
|
3462
3503
|
}
|
|
3463
3504
|
if (!matchesNode(nodeId)) return;
|
|
3464
|
-
|
|
3465
|
-
...prev,
|
|
3505
|
+
setPatch((prev) => ({
|
|
3506
|
+
...prev || {},
|
|
3466
3507
|
...nextProps
|
|
3467
3508
|
}));
|
|
3468
3509
|
};
|
|
@@ -3491,7 +3532,7 @@ function useLiveComposerProps(layoutNodeId, props) {
|
|
|
3491
3532
|
window.removeEventListener("message", onMessage);
|
|
3492
3533
|
};
|
|
3493
3534
|
}, [layoutNodeId]);
|
|
3494
|
-
return
|
|
3535
|
+
return patch ? { ...props, ...patch } : props;
|
|
3495
3536
|
}
|
|
3496
3537
|
function useComponentProps() {
|
|
3497
3538
|
const context = React.useContext(ComponentContext);
|
|
@@ -3527,23 +3568,12 @@ function Slot({
|
|
|
3527
3568
|
className
|
|
3528
3569
|
}) {
|
|
3529
3570
|
const context = React.useContext(ComponentContext);
|
|
3530
|
-
console.log(`[Slot:${name}] Rendering slot`, {
|
|
3531
|
-
hasContext: !!context,
|
|
3532
|
-
availableSlotKeys: context?.slots ? Object.keys(context.slots) : [],
|
|
3533
|
-
slotContent: context?.slots?.[name] ? "EXISTS" : "MISSING",
|
|
3534
|
-
contextSlots: context?.slots
|
|
3535
|
-
});
|
|
3536
3571
|
if (!context) {
|
|
3537
3572
|
console.warn(`[AmplifyUp SDK] Slot "${name}" used outside ComponentContextProvider`);
|
|
3538
3573
|
return null;
|
|
3539
3574
|
}
|
|
3540
3575
|
const slotContent = context.slots?.[name];
|
|
3541
3576
|
const isEmpty = !slotContent;
|
|
3542
|
-
console.log(`[Slot:${name}] Slot state`, {
|
|
3543
|
-
isEmpty,
|
|
3544
|
-
hasSlotContent: !!slotContent,
|
|
3545
|
-
slotContentType: slotContent ? typeof slotContent : "null"
|
|
3546
|
-
});
|
|
3547
3577
|
const isEditorMode = typeof window !== "undefined" && // Check for preview mode flag set by proxy
|
|
3548
3578
|
(window.__AMPLIFYUP_PREVIEW_MODE__ === true || // Check URL query params
|
|
3549
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)
|
|
@@ -3555,17 +3585,15 @@ function Slot({
|
|
|
3555
3585
|
return false;
|
|
3556
3586
|
}
|
|
3557
3587
|
})());
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
}
|
|
3566
|
-
|
|
3567
|
-
referrer: typeof window !== "undefined" && document.referrer ? document.referrer : void 0
|
|
3568
|
-
});
|
|
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
|
+
);
|
|
3569
3597
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3570
3598
|
"div",
|
|
3571
3599
|
{
|
|
@@ -3790,9 +3818,10 @@ function ComposerInlineField({
|
|
|
3790
3818
|
event.stopPropagation();
|
|
3791
3819
|
},
|
|
3792
3820
|
onClick: (event) => {
|
|
3821
|
+
if (!isComposerEditMode()) return;
|
|
3793
3822
|
const link = event.target?.closest?.("a");
|
|
3794
3823
|
if (link) event.preventDefault();
|
|
3795
|
-
if (render
|
|
3824
|
+
if (render) {
|
|
3796
3825
|
setEditing(true);
|
|
3797
3826
|
}
|
|
3798
3827
|
},
|
|
@@ -4205,7 +4234,7 @@ function LiveNodeRender({
|
|
|
4205
4234
|
layoutNodeId: nodeId
|
|
4206
4235
|
}) });
|
|
4207
4236
|
}
|
|
4208
|
-
function
|
|
4237
|
+
function AmplifyRendererInner({
|
|
4209
4238
|
renderComponent,
|
|
4210
4239
|
pageConfig: serverPageConfig,
|
|
4211
4240
|
loadingComponent,
|
|
@@ -4347,14 +4376,22 @@ function AmplifyRenderer({
|
|
|
4347
4376
|
return `${indent}- ${n.id} (${n.componentId || "?"})${slotsDesc ? "\n" + slotsDesc : ""}`;
|
|
4348
4377
|
}).join("\n");
|
|
4349
4378
|
};
|
|
4350
|
-
|
|
4379
|
+
sdkDebugOnce(
|
|
4380
|
+
`layoutTree:${pageConfig?.id || ""}:${pageConfig?.route || ""}`,
|
|
4381
|
+
"[AmplifyRenderer] layoutTree received:\n%s",
|
|
4382
|
+
describeLayoutTree(layoutTree2)
|
|
4383
|
+
);
|
|
4351
4384
|
if (typeof window !== "undefined" && window.parent && window.parent !== window) {
|
|
4352
4385
|
const message = {
|
|
4353
4386
|
type: "COMPONENT_TREE",
|
|
4354
4387
|
tree: componentTree
|
|
4355
4388
|
};
|
|
4356
4389
|
window.parent.postMessage(message, "*");
|
|
4357
|
-
|
|
4390
|
+
sdkDebug(
|
|
4391
|
+
"[AmplifyRenderer] Sent component tree from layoutTree:",
|
|
4392
|
+
componentTree.length,
|
|
4393
|
+
"root components"
|
|
4394
|
+
);
|
|
4358
4395
|
}
|
|
4359
4396
|
}, [pageConfig]);
|
|
4360
4397
|
React.useEffect(() => {
|
|
@@ -4505,7 +4542,7 @@ function AmplifyRenderer({
|
|
|
4505
4542
|
);
|
|
4506
4543
|
}
|
|
4507
4544
|
let slotChildren = {};
|
|
4508
|
-
|
|
4545
|
+
sdkDebugOnce(`node:${node.id}`, `[AmplifyRenderer] Rendering node ${node.id} (${node.componentId})`, {
|
|
4509
4546
|
hasSlots: !!(node.slots && node.slots.length > 0),
|
|
4510
4547
|
slotCount: node.slots?.length || 0,
|
|
4511
4548
|
slots: node.slots?.map((s) => ({ slotId: s.slotId, zoneId: s.zoneId, childrenCount: s.children?.length || 0 }))
|
|
@@ -4514,30 +4551,13 @@ function AmplifyRenderer({
|
|
|
4514
4551
|
for (const slot of node.slots) {
|
|
4515
4552
|
const slotKey = `${node.id}-${slot.slotId}`;
|
|
4516
4553
|
let childrenToRender = [];
|
|
4517
|
-
console.log(`[AmplifyRenderer] Processing slot ${slot.slotId} for node ${node.id}`, {
|
|
4518
|
-
slotKey,
|
|
4519
|
-
hasZoneId: !!slot.zoneId,
|
|
4520
|
-
hasVariants: !!slot.variants,
|
|
4521
|
-
hasVariantCache: !!variantCache[slotKey],
|
|
4522
|
-
directChildrenCount: slot.children?.length || 0
|
|
4523
|
-
});
|
|
4524
4554
|
if (slot.zoneId && slot.variants && variantCache[slotKey]) {
|
|
4525
4555
|
childrenToRender = variantCache[slotKey].children;
|
|
4526
|
-
console.log(`[AmplifyRenderer] Using cached variant for slot ${slot.slotId}`, {
|
|
4527
|
-
variantId: variantCache[slotKey].variantId,
|
|
4528
|
-
childrenCount: childrenToRender.length
|
|
4529
|
-
});
|
|
4530
4556
|
} else if (slot.zoneId && slot.variants) {
|
|
4531
4557
|
const defaultVariant = slot.variants.find((v) => v.isDefault);
|
|
4532
4558
|
childrenToRender = defaultVariant?.children || [];
|
|
4533
|
-
console.log(`[AmplifyRenderer] Using default variant for slot ${slot.slotId}`, {
|
|
4534
|
-
childrenCount: childrenToRender.length
|
|
4535
|
-
});
|
|
4536
4559
|
} else {
|
|
4537
4560
|
childrenToRender = Array.isArray(slot.children) ? slot.children : [];
|
|
4538
|
-
console.log(`[AmplifyRenderer] Using direct children for slot ${slot.slotId}`, {
|
|
4539
|
-
childrenCount: childrenToRender.length
|
|
4540
|
-
});
|
|
4541
4561
|
}
|
|
4542
4562
|
const safeChildren = Array.isArray(childrenToRender) ? childrenToRender : [];
|
|
4543
4563
|
slotChildren[slot.slotId] = /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -4552,10 +4572,6 @@ function AmplifyRenderer({
|
|
|
4552
4572
|
},
|
|
4553
4573
|
slot.slotId
|
|
4554
4574
|
);
|
|
4555
|
-
console.log(`[AmplifyRenderer] Created slot content for ${slot.slotId}`, {
|
|
4556
|
-
slotId: slot.slotId,
|
|
4557
|
-
renderedChildrenCount: childrenToRender.length
|
|
4558
|
-
});
|
|
4559
4575
|
}
|
|
4560
4576
|
}
|
|
4561
4577
|
const slotsToPass = Object.keys(slotChildren).length > 0 ? slotChildren : void 0;
|
|
@@ -4593,6 +4609,7 @@ function AmplifyRenderer({
|
|
|
4593
4609
|
}
|
|
4594
4610
|
) : layoutTree.map((node) => /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderNode(node) }, node.id)) });
|
|
4595
4611
|
}
|
|
4612
|
+
var AmplifyRenderer = React.memo(AmplifyRendererInner);
|
|
4596
4613
|
function defaultPreviewCanvas() {
|
|
4597
4614
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4598
4615
|
"div",
|
|
@@ -4696,6 +4713,12 @@ if (typeof window !== "undefined") {
|
|
|
4696
4713
|
}
|
|
4697
4714
|
}
|
|
4698
4715
|
var AmplifyUpContext = React.createContext(null);
|
|
4716
|
+
function normalizeRoutePath2(route) {
|
|
4717
|
+
if (!route) return "";
|
|
4718
|
+
const path = route.split("?")[0] || "/";
|
|
4719
|
+
if (path.length > 1 && path.endsWith("/")) return path.replace(/\/+$/, "");
|
|
4720
|
+
return path || "/";
|
|
4721
|
+
}
|
|
4699
4722
|
function AmplifyUpProvider({
|
|
4700
4723
|
children,
|
|
4701
4724
|
config,
|
|
@@ -4723,6 +4746,7 @@ function AmplifyUpProvider({
|
|
|
4723
4746
|
}
|
|
4724
4747
|
return currentPath;
|
|
4725
4748
|
};
|
|
4749
|
+
const loadedRouteRef = React.useRef(null);
|
|
4726
4750
|
const nextPathname = usePathname ? usePathname() : null;
|
|
4727
4751
|
const [pathname, setPathname] = React.useState(() => {
|
|
4728
4752
|
if (typeof window !== "undefined") {
|
|
@@ -4756,56 +4780,46 @@ function AmplifyUpProvider({
|
|
|
4756
4780
|
};
|
|
4757
4781
|
}
|
|
4758
4782
|
}, [nextPathname]);
|
|
4759
|
-
|
|
4760
|
-
let cancelled = false;
|
|
4761
|
-
const sdk = getSDK();
|
|
4762
|
-
sdk.init({
|
|
4763
|
-
...config,
|
|
4764
|
-
...pageContext ? { pageContext } : {}
|
|
4765
|
-
}).then(() => {
|
|
4766
|
-
if (!cancelled) {
|
|
4767
|
-
setInitialized(true);
|
|
4768
|
-
}
|
|
4769
|
-
}).catch((err) => {
|
|
4770
|
-
if (cancelled) return;
|
|
4771
|
-
console.error("Failed to initialize AmplifyUp SDK:", err);
|
|
4772
|
-
setError("Failed to initialize tracking");
|
|
4773
|
-
setLoading(false);
|
|
4774
|
-
});
|
|
4775
|
-
return () => {
|
|
4776
|
-
cancelled = true;
|
|
4777
|
-
};
|
|
4778
|
-
}, [config.trackingId, config.target, config.debug, config.dev, config.siteId, pageContext]);
|
|
4783
|
+
const pageContextKey = pageContext ? `${pageContext.resourceType}:${pageContext.key}` : "";
|
|
4779
4784
|
React.useEffect(() => {
|
|
4780
4785
|
if (!initialized || !pageContext) return;
|
|
4781
4786
|
getSDK().setPageContext(pageContext);
|
|
4782
|
-
}, [initialized,
|
|
4787
|
+
}, [initialized, pageContextKey]);
|
|
4783
4788
|
React.useEffect(() => {
|
|
4784
|
-
if (!initialized) return;
|
|
4785
4789
|
let cancelled = false;
|
|
4786
|
-
const
|
|
4790
|
+
const sdk = getSDK();
|
|
4791
|
+
const run = async () => {
|
|
4787
4792
|
try {
|
|
4793
|
+
await sdk.init({
|
|
4794
|
+
...config,
|
|
4795
|
+
...pageContext ? { pageContext } : {}
|
|
4796
|
+
});
|
|
4797
|
+
if (cancelled) return;
|
|
4798
|
+
if (pageContext) sdk.setPageContext(pageContext);
|
|
4788
4799
|
const actualRoute = getActualRoute();
|
|
4789
4800
|
if (!actualRoute) {
|
|
4801
|
+
setInitialized(true);
|
|
4790
4802
|
setLoading(false);
|
|
4791
4803
|
return;
|
|
4792
4804
|
}
|
|
4793
|
-
const sdk = getSDK();
|
|
4794
4805
|
sdk.routeChange(actualRoute);
|
|
4795
4806
|
const preview = isComposerPreview();
|
|
4796
4807
|
const overlay = preview || config.clientPersonalization !== false;
|
|
4797
4808
|
if (!overlay) {
|
|
4809
|
+
setInitialized(true);
|
|
4798
4810
|
setPageConfig(null);
|
|
4799
4811
|
setLoading(false);
|
|
4800
4812
|
return;
|
|
4801
4813
|
}
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4814
|
+
if (loadedRouteRef.current && loadedRouteRef.current !== actualRoute) {
|
|
4815
|
+
setPageConfig(null);
|
|
4816
|
+
setError(null);
|
|
4817
|
+
}
|
|
4805
4818
|
const edgeUrl = sdk.getEdgeUrl();
|
|
4806
4819
|
const orchestratorUrl = sdk.getOrchestratorUrl();
|
|
4807
4820
|
const trackingId = sdk.getTrackingId();
|
|
4808
4821
|
if (!trackingId || !orchestratorUrl || !edgeUrl) {
|
|
4822
|
+
setInitialized(true);
|
|
4809
4823
|
setError("SDK not initialized");
|
|
4810
4824
|
setLoading(false);
|
|
4811
4825
|
return;
|
|
@@ -4841,28 +4855,37 @@ function AmplifyUpProvider({
|
|
|
4841
4855
|
fetchOrchestratorPage: (route, isPreview) => sdk.fetchPageConfig(route, isPreview)
|
|
4842
4856
|
});
|
|
4843
4857
|
if (cancelled) return;
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4858
|
+
const nextConfig = result.pageConfig || {
|
|
4859
|
+
id: "default",
|
|
4860
|
+
route: actualRoute,
|
|
4861
|
+
title: "Page Not Configured",
|
|
4862
|
+
description: "This page has not been published yet.",
|
|
4863
|
+
layoutTree: []
|
|
4864
|
+
};
|
|
4865
|
+
setInitialized(true);
|
|
4866
|
+
setSource((prev) => prev === result.source ? prev : result.source);
|
|
4867
|
+
setMeta(
|
|
4868
|
+
(prev) => prev === result.meta || JSON.stringify(prev) === JSON.stringify(result.meta) ? prev : result.meta
|
|
4869
|
+
);
|
|
4870
|
+
setError((prev) => prev === result.error ? prev : result.error);
|
|
4871
|
+
setPageConfig((prev) => {
|
|
4872
|
+
if (prev && prev.id === nextConfig.id && normalizeRoutePath2(prev.route) === normalizeRoutePath2(nextConfig.route) && JSON.stringify(prev.layoutTree) === JSON.stringify(nextConfig.layoutTree)) {
|
|
4873
|
+
return prev;
|
|
4874
|
+
}
|
|
4875
|
+
return nextConfig;
|
|
4876
|
+
});
|
|
4877
|
+
if (result.pageConfig) {
|
|
4857
4878
|
sdk.applyResolvedPageData(
|
|
4858
4879
|
result.pageConfig.pageData || null,
|
|
4859
4880
|
result.pageConfig.route,
|
|
4860
4881
|
extractRouteParams(result.pageConfig.route, actualRoute)
|
|
4861
4882
|
);
|
|
4862
4883
|
}
|
|
4884
|
+
loadedRouteRef.current = actualRoute;
|
|
4863
4885
|
} catch (err) {
|
|
4864
4886
|
if (cancelled) return;
|
|
4865
4887
|
console.error("Error fetching page config:", err);
|
|
4888
|
+
setInitialized(true);
|
|
4866
4889
|
setError(err instanceof Error ? err.message : "Unknown error");
|
|
4867
4890
|
setSource(null);
|
|
4868
4891
|
setMeta(null);
|
|
@@ -4870,11 +4893,20 @@ function AmplifyUpProvider({
|
|
|
4870
4893
|
if (!cancelled) setLoading(false);
|
|
4871
4894
|
}
|
|
4872
4895
|
};
|
|
4873
|
-
void
|
|
4896
|
+
void run();
|
|
4874
4897
|
return () => {
|
|
4875
4898
|
cancelled = true;
|
|
4876
4899
|
};
|
|
4877
|
-
}, [
|
|
4900
|
+
}, [
|
|
4901
|
+
pathname,
|
|
4902
|
+
config.trackingId,
|
|
4903
|
+
config.target,
|
|
4904
|
+
config.debug,
|
|
4905
|
+
config.dev,
|
|
4906
|
+
config.siteId,
|
|
4907
|
+
config.clientPersonalization,
|
|
4908
|
+
pageContextKey
|
|
4909
|
+
]);
|
|
4878
4910
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4879
4911
|
AmplifyUpContext.Provider,
|
|
4880
4912
|
{
|