@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.
@@ -829,7 +829,9 @@ var AmplifyUpSDK = class {
829
829
  this.page(url);
830
830
  this.lastTrackedPath = url;
831
831
  this.setupPageEngagement();
832
- this.installHistoryHooks();
832
+ if (!this.isNextJsApp()) {
833
+ this.installHistoryHooks();
834
+ }
833
835
  }
834
836
  }
835
837
  if (this.config?.debug && this.initialized) {
@@ -1082,9 +1084,21 @@ var AmplifyUpSDK = class {
1082
1084
  console.log("[AmplifyUp SDK] Route change page view", path);
1083
1085
  }
1084
1086
  }
1087
+ /** True on Next.js (App or Pages). Do not patch history on these apps. */
1088
+ isNextJsApp() {
1089
+ if (typeof window === "undefined" || typeof document === "undefined") {
1090
+ return false;
1091
+ }
1092
+ const win = window;
1093
+ if (win.next) return true;
1094
+ if (document.getElementById("__next")) return true;
1095
+ if (document.querySelector('script[src*="/_next/"]')) return true;
1096
+ return false;
1097
+ }
1085
1098
  /**
1086
1099
  * Patch history.pushState / replaceState + popstate for non-React SPAs.
1087
- * React/Next apps should also call routeChange from the provider.
1100
+ * Next.js apps use AmplifyUpProvider.routeChange via usePathname instead —
1101
+ * wrapping history breaks App Router <Link> (no RSC request).
1088
1102
  */
1089
1103
  installHistoryHooks() {
1090
1104
  if (typeof window === "undefined" || this.historyHooksInstalled) return;
@@ -2933,11 +2947,9 @@ var refreshEventTracking = () => getSDK().refreshEventTracking();
2933
2947
  getSDK();
2934
2948
  react.createContext(null);
2935
2949
  function useLiveComposerProps(layoutNodeId, props) {
2936
- const [live, setLive] = react.useState(props);
2937
- react.useEffect(() => {
2938
- setLive(props);
2939
- }, [props]);
2950
+ const [patch, setPatch] = react.useState(null);
2940
2951
  react.useEffect(() => {
2952
+ setPatch(null);
2941
2953
  const matchesNode = (nodeId) => {
2942
2954
  if (nodeId && layoutNodeId && String(nodeId) !== String(layoutNodeId)) {
2943
2955
  return false;
@@ -2947,15 +2959,15 @@ function useLiveComposerProps(layoutNodeId, props) {
2947
2959
  const applyField = (fieldName, value, nodeId) => {
2948
2960
  if (!fieldName || typeof fieldName !== "string") return;
2949
2961
  if (!matchesNode(nodeId)) return;
2950
- setLive((prev) => ({ ...prev, [fieldName]: value }));
2962
+ setPatch((prev) => ({ ...prev || {}, [fieldName]: value }));
2951
2963
  };
2952
2964
  const applyProps = (nextProps, nodeId) => {
2953
2965
  if (!nextProps || typeof nextProps !== "object" || Array.isArray(nextProps)) {
2954
2966
  return;
2955
2967
  }
2956
2968
  if (!matchesNode(nodeId)) return;
2957
- setLive((prev) => ({
2958
- ...prev,
2969
+ setPatch((prev) => ({
2970
+ ...prev || {},
2959
2971
  ...nextProps
2960
2972
  }));
2961
2973
  };
@@ -2984,7 +2996,7 @@ function useLiveComposerProps(layoutNodeId, props) {
2984
2996
  window.removeEventListener("message", onMessage);
2985
2997
  };
2986
2998
  }, [layoutNodeId]);
2987
- return live;
2999
+ return patch ? { ...props, ...patch } : props;
2988
3000
  }
2989
3001
  var usePathname = null;
2990
3002
  if (typeof window !== "undefined") {