@nativescript/angular 21.0.1-alpha.4 → 21.0.1-alpha.5

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.
@@ -9866,6 +9866,25 @@ function clearAngularHmrRouteHistory() {
9866
9866
  const g = getGlobalState();
9867
9867
  delete g[HISTORY_KEY];
9868
9868
  }
9869
+ /**
9870
+ * Replace the entire live back-stack mirror with a single URL. Mirrors
9871
+ * NativeScript's `clearHistory: true` navigation option, which collapses
9872
+ * the native page stack down to the destination — without this, the HMR
9873
+ * snapshot would still carry every URL the user passed through before
9874
+ * the reset (e.g. login screens that auth-gates now hide), and the next
9875
+ * reboot would walk through every one of them as a forward navigation.
9876
+ *
9877
+ * An empty / unparseable `value` clears the mirror entirely.
9878
+ */
9879
+ function resetAngularHmrRouteHistoryToUrl(value) {
9880
+ const url = normalizeAngularHmrRouteUrl(value);
9881
+ if (!url) {
9882
+ writeHistoryArray(HISTORY_KEY, []);
9883
+ return null;
9884
+ }
9885
+ writeHistoryArray(HISTORY_KEY, [url]);
9886
+ return url;
9887
+ }
9869
9888
  /**
9870
9889
  * Snapshot the live back-stack mirror under the pending-history slot so the
9871
9890
  * next bootstrap can read it. Called from the HMR capture hook.
@@ -10157,6 +10176,34 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImpor
10157
10176
  type: Injectable
10158
10177
  }], ctorParameters: () => [{ type: i1$3.Router }] });
10159
10178
 
10179
+ /**
10180
+ * Read NativeScript's `clearHistory: true` navigation extra off the active
10181
+ * Angular navigation. Defensive against test mocks and bare `Router`-like
10182
+ * shapes that don't expose `getCurrentNavigation` (e.g. earlier Angular
10183
+ * versions and the unit-test mocks in `hmr-route-state-tracker.spec.ts`).
10184
+ *
10185
+ * `clearHistory` is the NativeScript-only signal that
10186
+ * `NSLocationStrategy._beginPageNavigation` uses to collapse the native page
10187
+ * stack down to the destination. We mirror that on the HMR side so a
10188
+ * subsequent reboot doesn't replay URLs the user can no longer reach (the
10189
+ * canonical example: `/`, `/signup-landing`, `/login` after the auth flow
10190
+ * navigated to `/talk/(todayTab:today)` with `clearHistory: true`).
10191
+ */
10192
+ function readClearHistoryFromRouter(router) {
10193
+ const getCurrentNavigation = router.getCurrentNavigation;
10194
+ if (typeof getCurrentNavigation !== 'function') {
10195
+ return false;
10196
+ }
10197
+ let navigation;
10198
+ try {
10199
+ navigation = getCurrentNavigation.call(router);
10200
+ }
10201
+ catch {
10202
+ return false;
10203
+ }
10204
+ const extras = navigation?.extras;
10205
+ return !!extras?.clearHistory;
10206
+ }
10160
10207
  class NativeScriptAngularHmrRouteTracker {
10161
10208
  constructor(router) {
10162
10209
  this.router = router;
@@ -10165,6 +10212,12 @@ class NativeScriptAngularHmrRouteTracker {
10165
10212
  // `NavigationEnd` we can pop our mirror instead of pushing a duplicate entry.
10166
10213
  this.currentNavigationIsPopstate = false;
10167
10214
  this.currentNavigationReplaceUrl = false;
10215
+ // Tracks whether the active navigation was started with NativeScript's
10216
+ // `clearHistory: true` extra (read off `router.getCurrentNavigation()` at
10217
+ // `NavigationStart`). When set, the matching `NavigationEnd` collapses the
10218
+ // mirror down to just the destination URL — see
10219
+ // `resetAngularHmrRouteHistoryToUrl` for the rationale.
10220
+ this.currentNavigationClearsHistory = false;
10168
10221
  if (!isAngularHmrEnabled()) {
10169
10222
  return;
10170
10223
  }
@@ -10174,6 +10227,7 @@ class NativeScriptAngularHmrRouteTracker {
10174
10227
  if (event instanceof NavigationStart) {
10175
10228
  this.currentNavigationIsPopstate = event.navigationTrigger === 'popstate';
10176
10229
  this.currentNavigationReplaceUrl = !!event.restoredState;
10230
+ this.currentNavigationClearsHistory = readClearHistoryFromRouter(this.router);
10177
10231
  return;
10178
10232
  }
10179
10233
  if (event instanceof NavigationEnd) {
@@ -10181,7 +10235,14 @@ class NativeScriptAngularHmrRouteTracker {
10181
10235
  writeAngularHmrRouteState(url, {
10182
10236
  source: 'navigation-end',
10183
10237
  });
10184
- if (this.currentNavigationIsPopstate) {
10238
+ if (this.currentNavigationClearsHistory) {
10239
+ // NativeScript collapsed the native page stack to this single
10240
+ // destination. Mirror that on the HMR side so a future reboot
10241
+ // replays only what the user can still navigate back through —
10242
+ // not every URL they passed through before the reset.
10243
+ resetAngularHmrRouteHistoryToUrl(url);
10244
+ }
10245
+ else if (this.currentNavigationIsPopstate) {
10185
10246
  // The user (or NSLocationStrategy.back()) walked the back-stack down
10186
10247
  // by one page; mirror that by dropping the top of our snapshot so a
10187
10248
  // subsequent HMR reboot doesn't carry the popped page back into view.
@@ -10195,6 +10256,7 @@ class NativeScriptAngularHmrRouteTracker {
10195
10256
  }
10196
10257
  this.currentNavigationIsPopstate = false;
10197
10258
  this.currentNavigationReplaceUrl = false;
10259
+ this.currentNavigationClearsHistory = false;
10198
10260
  }
10199
10261
  });
10200
10262
  }