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