@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/index.d.mts CHANGED
@@ -246,9 +246,12 @@ declare class AmplifyUpSDK {
246
246
  * No-op when the path has not changed. Safe for React Strict Mode remounts.
247
247
  */
248
248
  routeChange(url?: string, properties?: EventProperties): void;
249
+ /** True on Next.js (App or Pages). Do not patch history on these apps. */
250
+ private isNextJsApp;
249
251
  /**
250
252
  * Patch history.pushState / replaceState + popstate for non-React SPAs.
251
- * React/Next apps should also call routeChange from the provider.
253
+ * Next.js apps use AmplifyUpProvider.routeChange via usePathname instead —
254
+ * wrapping history breaks App Router <Link> (no RSC request).
252
255
  */
253
256
  private installHistoryHooks;
254
257
  /**
package/dist/index.d.ts CHANGED
@@ -246,9 +246,12 @@ declare class AmplifyUpSDK {
246
246
  * No-op when the path has not changed. Safe for React Strict Mode remounts.
247
247
  */
248
248
  routeChange(url?: string, properties?: EventProperties): void;
249
+ /** True on Next.js (App or Pages). Do not patch history on these apps. */
250
+ private isNextJsApp;
249
251
  /**
250
252
  * Patch history.pushState / replaceState + popstate for non-React SPAs.
251
- * React/Next apps should also call routeChange from the provider.
253
+ * Next.js apps use AmplifyUpProvider.routeChange via usePathname instead —
254
+ * wrapping history breaks App Router <Link> (no RSC request).
252
255
  */
253
256
  private installHistoryHooks;
254
257
  /**
package/dist/index.js CHANGED
@@ -1168,7 +1168,9 @@ var AmplifyUpSDK = class {
1168
1168
  this.page(url);
1169
1169
  this.lastTrackedPath = url;
1170
1170
  this.setupPageEngagement();
1171
- this.installHistoryHooks();
1171
+ if (!this.isNextJsApp()) {
1172
+ this.installHistoryHooks();
1173
+ }
1172
1174
  }
1173
1175
  }
1174
1176
  if (this.config?.debug && this.initialized) {
@@ -1421,9 +1423,21 @@ var AmplifyUpSDK = class {
1421
1423
  console.log("[AmplifyUp SDK] Route change page view", path);
1422
1424
  }
1423
1425
  }
1426
+ /** True on Next.js (App or Pages). Do not patch history on these apps. */
1427
+ isNextJsApp() {
1428
+ if (typeof window === "undefined" || typeof document === "undefined") {
1429
+ return false;
1430
+ }
1431
+ const win = window;
1432
+ if (win.next) return true;
1433
+ if (document.getElementById("__next")) return true;
1434
+ if (document.querySelector('script[src*="/_next/"]')) return true;
1435
+ return false;
1436
+ }
1424
1437
  /**
1425
1438
  * Patch history.pushState / replaceState + popstate for non-React SPAs.
1426
- * React/Next apps should also call routeChange from the provider.
1439
+ * Next.js apps use AmplifyUpProvider.routeChange via usePathname instead —
1440
+ * wrapping history breaks App Router <Link> (no RSC request).
1427
1441
  */
1428
1442
  installHistoryHooks() {
1429
1443
  if (typeof window === "undefined" || this.historyHooksInstalled) return;