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

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.
@@ -7447,13 +7447,20 @@ const DEFAULT_INVALIDATE_EVENT = 'ns:cache-invalidate';
7447
7447
  * type is the only one in play; `vite/client`-aware apps still get
7448
7448
  * their own typing on `import.meta.hot` at every call site outside
7449
7449
  * this module.
7450
+ *
7451
+ * Webpack-CommonJS compatibility: every `import.meta` reference here
7452
+ * is a member expression (`import.meta['hot']`). Webpack statically
7453
+ * rewrites both dot- and bracket-style member access to `undefined`
7454
+ * in CommonJS output, so the emitted bundle never carries a literal
7455
+ * bare `import.meta` token. A bare `import.meta` would survive into
7456
+ * the bundle and crash V8 with "Cannot use 'import.meta' outside a
7457
+ * module" the moment the chunk is `require()`d. Vite leaves
7458
+ * `import.meta['hot']` intact and resolves it to the per-module hot
7459
+ * context, so the same code works in both pipelines.
7450
7460
  */
7451
7461
  function readImportMetaHot() {
7452
7462
  try {
7453
- const meta = typeof import.meta !== 'undefined'
7454
- ? import.meta
7455
- : undefined;
7456
- return meta?.hot;
7463
+ return import.meta['hot'];
7457
7464
  }
7458
7465
  catch {
7459
7466
  return undefined;
@@ -7879,10 +7886,12 @@ function getOrCreateSharedStore() {
7879
7886
  }
7880
7887
  function hasImportMetaHot() {
7881
7888
  try {
7882
- const meta = typeof import.meta !== 'undefined'
7883
- ? import.meta
7884
- : undefined;
7885
- return !!meta?.hot;
7889
+ // Member-expression access only — webpack rewrites `import.meta['hot']`
7890
+ // to `undefined` in CommonJS bundles (so `!!undefined` → `false`),
7891
+ // while Vite leaves it as the per-module hot context. A bare
7892
+ // `typeof import.meta` would survive into the bundle and crash V8
7893
+ // with "Cannot use 'import.meta' outside a module" on `require()`.
7894
+ return !!import.meta['hot'];
7886
7895
  }
7887
7896
  catch {
7888
7897
  return false;
@@ -9866,6 +9875,25 @@ function clearAngularHmrRouteHistory() {
9866
9875
  const g = getGlobalState();
9867
9876
  delete g[HISTORY_KEY];
9868
9877
  }
9878
+ /**
9879
+ * Replace the entire live back-stack mirror with a single URL. Mirrors
9880
+ * NativeScript's `clearHistory: true` navigation option, which collapses
9881
+ * the native page stack down to the destination — without this, the HMR
9882
+ * snapshot would still carry every URL the user passed through before
9883
+ * the reset (e.g. login screens that auth-gates now hide), and the next
9884
+ * reboot would walk through every one of them as a forward navigation.
9885
+ *
9886
+ * An empty / unparseable `value` clears the mirror entirely.
9887
+ */
9888
+ function resetAngularHmrRouteHistoryToUrl(value) {
9889
+ const url = normalizeAngularHmrRouteUrl(value);
9890
+ if (!url) {
9891
+ writeHistoryArray(HISTORY_KEY, []);
9892
+ return null;
9893
+ }
9894
+ writeHistoryArray(HISTORY_KEY, [url]);
9895
+ return url;
9896
+ }
9869
9897
  /**
9870
9898
  * Snapshot the live back-stack mirror under the pending-history slot so the
9871
9899
  * next bootstrap can read it. Called from the HMR capture hook.
@@ -10157,6 +10185,34 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImpor
10157
10185
  type: Injectable
10158
10186
  }], ctorParameters: () => [{ type: i1$3.Router }] });
10159
10187
 
10188
+ /**
10189
+ * Read NativeScript's `clearHistory: true` navigation extra off the active
10190
+ * Angular navigation. Defensive against test mocks and bare `Router`-like
10191
+ * shapes that don't expose `getCurrentNavigation` (e.g. earlier Angular
10192
+ * versions and the unit-test mocks in `hmr-route-state-tracker.spec.ts`).
10193
+ *
10194
+ * `clearHistory` is the NativeScript-only signal that
10195
+ * `NSLocationStrategy._beginPageNavigation` uses to collapse the native page
10196
+ * stack down to the destination. We mirror that on the HMR side so a
10197
+ * subsequent reboot doesn't replay URLs the user can no longer reach (the
10198
+ * canonical example: `/`, `/signup-landing`, `/login` after the auth flow
10199
+ * navigated to `/talk/(todayTab:today)` with `clearHistory: true`).
10200
+ */
10201
+ function readClearHistoryFromRouter(router) {
10202
+ const getCurrentNavigation = router.getCurrentNavigation;
10203
+ if (typeof getCurrentNavigation !== 'function') {
10204
+ return false;
10205
+ }
10206
+ let navigation;
10207
+ try {
10208
+ navigation = getCurrentNavigation.call(router);
10209
+ }
10210
+ catch {
10211
+ return false;
10212
+ }
10213
+ const extras = navigation?.extras;
10214
+ return !!extras?.clearHistory;
10215
+ }
10160
10216
  class NativeScriptAngularHmrRouteTracker {
10161
10217
  constructor(router) {
10162
10218
  this.router = router;
@@ -10165,6 +10221,12 @@ class NativeScriptAngularHmrRouteTracker {
10165
10221
  // `NavigationEnd` we can pop our mirror instead of pushing a duplicate entry.
10166
10222
  this.currentNavigationIsPopstate = false;
10167
10223
  this.currentNavigationReplaceUrl = false;
10224
+ // Tracks whether the active navigation was started with NativeScript's
10225
+ // `clearHistory: true` extra (read off `router.getCurrentNavigation()` at
10226
+ // `NavigationStart`). When set, the matching `NavigationEnd` collapses the
10227
+ // mirror down to just the destination URL — see
10228
+ // `resetAngularHmrRouteHistoryToUrl` for the rationale.
10229
+ this.currentNavigationClearsHistory = false;
10168
10230
  if (!isAngularHmrEnabled()) {
10169
10231
  return;
10170
10232
  }
@@ -10174,6 +10236,7 @@ class NativeScriptAngularHmrRouteTracker {
10174
10236
  if (event instanceof NavigationStart) {
10175
10237
  this.currentNavigationIsPopstate = event.navigationTrigger === 'popstate';
10176
10238
  this.currentNavigationReplaceUrl = !!event.restoredState;
10239
+ this.currentNavigationClearsHistory = readClearHistoryFromRouter(this.router);
10177
10240
  return;
10178
10241
  }
10179
10242
  if (event instanceof NavigationEnd) {
@@ -10181,7 +10244,14 @@ class NativeScriptAngularHmrRouteTracker {
10181
10244
  writeAngularHmrRouteState(url, {
10182
10245
  source: 'navigation-end',
10183
10246
  });
10184
- if (this.currentNavigationIsPopstate) {
10247
+ if (this.currentNavigationClearsHistory) {
10248
+ // NativeScript collapsed the native page stack to this single
10249
+ // destination. Mirror that on the HMR side so a future reboot
10250
+ // replays only what the user can still navigate back through —
10251
+ // not every URL they passed through before the reset.
10252
+ resetAngularHmrRouteHistoryToUrl(url);
10253
+ }
10254
+ else if (this.currentNavigationIsPopstate) {
10185
10255
  // The user (or NSLocationStrategy.back()) walked the back-stack down
10186
10256
  // by one page; mirror that by dropping the top of our snapshot so a
10187
10257
  // subsequent HMR reboot doesn't carry the popped page back into view.
@@ -10195,6 +10265,7 @@ class NativeScriptAngularHmrRouteTracker {
10195
10265
  }
10196
10266
  this.currentNavigationIsPopstate = false;
10197
10267
  this.currentNavigationReplaceUrl = false;
10268
+ this.currentNavigationClearsHistory = false;
10198
10269
  }
10199
10270
  });
10200
10271
  }