@real-router/angular 0.21.0 → 0.22.0

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.
@@ -1338,6 +1338,57 @@ function createViewTransitions(router) {
1338
1338
  * (#1798), which is the doctrine's own caveat and travels with it.
1339
1339
  */
1340
1340
  const objectKeys = Object.keys;
1341
+ /**
1342
+ * The brand `packages/core/src/internals.ts` puts on every router it registers,
1343
+ * RE-DECLARED rather than imported (#2294).
1344
+ *
1345
+ * ⚑ `Symbol.for` makes the two the same symbol, so **the STRING is the
1346
+ * contract** — change it in one place and this warning silently stops firing.
1347
+ * The same shape core already uses for `CONFIG_FAULT`, declared twice across a
1348
+ * boundary it cannot import over, and pinned the same way: the guard is
1349
+ * `foreign-router-href-2294.test.ts`, whose cells fail on exactly that drift.
1350
+ */
1351
+ const ROUTER_BRAND = Symbol.for("real-router.router");
1352
+ /**
1353
+ * Is this a real router that core cannot read — as opposed to the `Router`-SHAPED
1354
+ * double this helper accepts by contract?
1355
+ *
1356
+ * ⚠ Read defensively: the argument is the caller's object and may be a `Proxy`
1357
+ * whose `get` trap throws. A diagnostic that throws would change where the error
1358
+ * comes FROM, which is the #1572 class, so a throwing read means "cannot tell".
1359
+ */
1360
+ function isUnreadableRouter(candidate) {
1361
+ try {
1362
+ return (candidate?.[ROUTER_BRAND] === true);
1363
+ }
1364
+ catch {
1365
+ return false;
1366
+ }
1367
+ }
1368
+ /**
1369
+ * The registry lookup, ALONE — and standing alone is what makes the warning
1370
+ * correct (#2294).
1371
+ *
1372
+ * ⚑ Inside the resolve-and-print `try` this could not be told apart from a
1373
+ * `forwardState` that threw for a reason the arm handles deliberately. The
1374
+ * channel guard (#1572) is exactly that, and it fires on a router that IS
1375
+ * registered and IS branded — so a check made there would report duplicated core
1376
+ * on a perfectly healthy one.
1377
+ */
1378
+ function readPluginApi(router, routeName) {
1379
+ try {
1380
+ return getPluginApi(router);
1381
+ }
1382
+ catch {
1383
+ if (isUnreadableRouter(router)) {
1384
+ console.error(`[real-router] Route "${routeName}" rendered its LITERAL path: this IS a router, ` +
1385
+ "but not one this copy of @real-router/core built, so `forwardTo` was not resolved. " +
1386
+ "It is either wrapped in a Proxy (Vue `reactive()` / Pinia — store it with `markRaw`), " +
1387
+ "or your dependency tree holds two copies of @real-router/core — dedupe it to one.");
1388
+ }
1389
+ return undefined;
1390
+ }
1391
+ }
1341
1392
  /**
1342
1393
  * Collapses a `<Link>`'s two prop forms (RFC-4 M2 B2, #1548) into one channel
1343
1394
  * triple:
@@ -1516,6 +1567,7 @@ function buildHref(router, routeName, routeParams, routeSearch, hash) {
1516
1567
  // `packages/react/tests/functional/dom-utils/forwarding-link-href-2250.test.ts`
1517
1568
  // owns that.
1518
1569
  let resolved;
1570
+ const api = readPluginApi(router, routeName);
1519
1571
  try {
1520
1572
  // ⚠ **`forwardState`, not `buildNavigationState`.** Both resolve the whole
1521
1573
  // chain, and the href is identical — but the committing door opts into
@@ -1533,9 +1585,16 @@ function buildHref(router, routeName, routeParams, routeSearch, hash) {
1533
1585
  // two invocations per href — a stateful one double-counts. Cost is the
1534
1586
  // lesser half: +1333 ns per href with `search-schema` +
1535
1587
  // `persistent-params` installed, per `<Link>` per render.
1536
- const api = getPluginApi(router);
1537
- const forwarded = api.forwardState(routeName, routeParams, routeSearch);
1538
- resolved = api.buildPathResolved(forwarded.name, forwarded.params, forwarded.search);
1588
+ //
1589
+ // ⚠ `api?.` is a TYPE gate, not a runtime guard, and naming it so keeps it
1590
+ // from being read as one: calling `forwardState` on `undefined` throws
1591
+ // into the same `catch` for the same outcome, so a mutant dropping the
1592
+ // check is EQUIVALENT. What it buys is that TypeScript can see the call is
1593
+ // safe below a lookup that may have failed (#2294).
1594
+ const forwarded = api?.forwardState(routeName, routeParams, routeSearch);
1595
+ resolved =
1596
+ forwarded &&
1597
+ api?.buildPathResolved(forwarded.name, forwarded.params, forwarded.search);
1539
1598
  }
1540
1599
  catch {
1541
1600
  resolved = undefined;