@amplifyup/sdk 0.1.51 → 0.1.53

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;