@amplifyup/sdk 0.1.52 → 0.1.54

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
@@ -1221,7 +1221,9 @@ var AmplifyUpSDK = class {
1221
1221
  this.page(url);
1222
1222
  this.lastTrackedPath = url;
1223
1223
  this.setupPageEngagement();
1224
- this.installHistoryHooks();
1224
+ if (!this.isNextJsApp()) {
1225
+ this.installHistoryHooks();
1226
+ }
1225
1227
  }
1226
1228
  }
1227
1229
  if (this.config?.debug && this.initialized) {
@@ -1474,9 +1476,21 @@ var AmplifyUpSDK = class {
1474
1476
  console.log("[AmplifyUp SDK] Route change page view", path);
1475
1477
  }
1476
1478
  }
1479
+ /** True on Next.js (App or Pages). Do not patch history on these apps. */
1480
+ isNextJsApp() {
1481
+ if (typeof window === "undefined" || typeof document === "undefined") {
1482
+ return false;
1483
+ }
1484
+ const win = window;
1485
+ if (win.next) return true;
1486
+ if (document.getElementById("__next")) return true;
1487
+ if (document.querySelector('script[src*="/_next/"]')) return true;
1488
+ return false;
1489
+ }
1477
1490
  /**
1478
1491
  * Patch history.pushState / replaceState + popstate for non-React SPAs.
1479
- * React/Next apps should also call routeChange from the provider.
1492
+ * Next.js apps use AmplifyUpProvider.routeChange via usePathname instead —
1493
+ * wrapping history breaks App Router <Link> (no RSC request).
1480
1494
  */
1481
1495
  installHistoryHooks() {
1482
1496
  if (typeof window === "undefined" || this.historyHooksInstalled) return;
@@ -3420,11 +3434,9 @@ function EmptySlotHint({
3420
3434
  }
3421
3435
  var ComponentContext = createContext(null);
3422
3436
  function useLiveComposerProps(layoutNodeId, props) {
3423
- const [live, setLive] = useState(props);
3424
- useEffect(() => {
3425
- setLive(props);
3426
- }, [props]);
3437
+ const [patch, setPatch] = useState(null);
3427
3438
  useEffect(() => {
3439
+ setPatch(null);
3428
3440
  const matchesNode = (nodeId) => {
3429
3441
  if (nodeId && layoutNodeId && String(nodeId) !== String(layoutNodeId)) {
3430
3442
  return false;
@@ -3434,15 +3446,15 @@ function useLiveComposerProps(layoutNodeId, props) {
3434
3446
  const applyField = (fieldName, value, nodeId) => {
3435
3447
  if (!fieldName || typeof fieldName !== "string") return;
3436
3448
  if (!matchesNode(nodeId)) return;
3437
- setLive((prev) => ({ ...prev, [fieldName]: value }));
3449
+ setPatch((prev) => ({ ...prev || {}, [fieldName]: value }));
3438
3450
  };
3439
3451
  const applyProps = (nextProps, nodeId) => {
3440
3452
  if (!nextProps || typeof nextProps !== "object" || Array.isArray(nextProps)) {
3441
3453
  return;
3442
3454
  }
3443
3455
  if (!matchesNode(nodeId)) return;
3444
- setLive((prev) => ({
3445
- ...prev,
3456
+ setPatch((prev) => ({
3457
+ ...prev || {},
3446
3458
  ...nextProps
3447
3459
  }));
3448
3460
  };
@@ -3471,7 +3483,7 @@ function useLiveComposerProps(layoutNodeId, props) {
3471
3483
  window.removeEventListener("message", onMessage);
3472
3484
  };
3473
3485
  }, [layoutNodeId]);
3474
- return live;
3486
+ return patch ? { ...props, ...patch } : props;
3475
3487
  }
3476
3488
  function useComponentProps() {
3477
3489
  const context = useContext(ComponentContext);
@@ -3770,9 +3782,10 @@ function ComposerInlineField({
3770
3782
  event.stopPropagation();
3771
3783
  },
3772
3784
  onClick: (event) => {
3785
+ if (!isComposerEditMode()) return;
3773
3786
  const link = event.target?.closest?.("a");
3774
3787
  if (link) event.preventDefault();
3775
- if (render && isComposerEditMode()) {
3788
+ if (render) {
3776
3789
  setEditing(true);
3777
3790
  }
3778
3791
  },