@real-router/angular 0.20.2 → 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:
|
|
@@ -1488,14 +1539,19 @@ function buildHref(router, routeName, routeParams, routeSearch, hash) {
|
|
|
1488
1539
|
// lands, and the click resolves `forwardTo`. `router.buildPath` alone is
|
|
1489
1540
|
// class LITERAL by record and answers about the route it was NAMED —
|
|
1490
1541
|
// INVARIANTS #8 keeps that so a plugin can build a state for an alias
|
|
1491
|
-
// without being teleported off it — so the chain is resolved FIRST and
|
|
1492
|
-
//
|
|
1493
|
-
//
|
|
1542
|
+
// without being teleported off it — so the chain is resolved FIRST and the
|
|
1543
|
+
// printer prints the target. The door choice belongs here rather than one
|
|
1544
|
+
// layer down.
|
|
1494
1545
|
//
|
|
1495
|
-
// ⚠ The `??`
|
|
1496
|
-
//
|
|
1497
|
-
// `
|
|
1498
|
-
//
|
|
1546
|
+
// ⚠ **The `??` is not reached by a name the table does not hold, and the
|
|
1547
|
+
// claim that it was described a door this arm stopped calling.** That read
|
|
1548
|
+
// `buildNavigationState`, which answers `undefined` for an unknown route;
|
|
1549
|
+
// since #2265 the resolving door is `forwardState`, which ANSWERS for one
|
|
1550
|
+
// (measured — it does not validate the name), leaving the printer to throw.
|
|
1551
|
+
// `packages/react/INVARIANTS.md` row 3 still holds — `Both throw →
|
|
1552
|
+
// undefined + console.error` — but it is reached by both printers throwing,
|
|
1553
|
+
// not by a `undefined` the `??` absorbs. What the `??` IS load-bearing for
|
|
1554
|
+
// is the two cases below.
|
|
1499
1555
|
//
|
|
1500
1556
|
// ⚠ **The fallback is also where the channel guard lands (#1572).** A route's
|
|
1501
1557
|
// declared query name handed in the PATH bag makes the class-① door throw
|
|
@@ -1511,14 +1567,34 @@ function buildHref(router, routeName, routeParams, routeSearch, hash) {
|
|
|
1511
1567
|
// `packages/react/tests/functional/dom-utils/forwarding-link-href-2250.test.ts`
|
|
1512
1568
|
// owns that.
|
|
1513
1569
|
let resolved;
|
|
1570
|
+
const api = readPluginApi(router, routeName);
|
|
1514
1571
|
try {
|
|
1515
1572
|
// ⚠ **`forwardState`, not `buildNavigationState`.** Both resolve the whole
|
|
1516
1573
|
// chain, and the href is identical — but the committing door opts into
|
|
1517
1574
|
// `reportUndeclaredParamKey`, and an href COMMITS NOTHING. That diagnostic
|
|
1518
1575
|
// is for a state you are about to persist, which is why `canNavigateTo`
|
|
1519
1576
|
// is silent despite sharing `navigate`'s form (#2248 / #1581).
|
|
1520
|
-
|
|
1521
|
-
|
|
1577
|
+
// ⚑ **`buildPathResolved`, not `router.buildPath` — ONE href is ONE pass
|
|
1578
|
+
// of the chain (#2260).** The facade's printer runs the `forwardState`
|
|
1579
|
+
// seam a door lower (#2087), which is right for a caller holding a raw
|
|
1580
|
+
// intent and a SECOND pass for this one, which just resolved. Counted,
|
|
1581
|
+
// because nothing in either door's source says "twice": the second pass
|
|
1582
|
+
// is what two individually-correct doors compose to.
|
|
1583
|
+
//
|
|
1584
|
+
// ⚠ A plugin author registers one interceptor and has no reason to expect
|
|
1585
|
+
// two invocations per href — a stateful one double-counts. Cost is the
|
|
1586
|
+
// lesser half: +1333 ns per href with `search-schema` +
|
|
1587
|
+
// `persistent-params` installed, per `<Link>` per render.
|
|
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);
|
|
1522
1598
|
}
|
|
1523
1599
|
catch {
|
|
1524
1600
|
resolved = undefined;
|