@real-router/angular 0.21.0 → 0.22.1

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/README.md CHANGED
@@ -640,12 +640,12 @@ Existing `provideRealRouter(router)` is unchanged — keep using it for SPA / po
640
640
 
641
641
  **SSR / SSG examples** — `provideRealRouterFactory({ baseRouter, plugins, deps })`:
642
642
 
643
- | Example | Demonstrates |
644
- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
645
- | [`examples/web/angular/ssr-examples/ssr/`](../../examples/web/angular/ssr-examples/ssr) | Classical SSR with cookie-based DI, auth guards, nested loaders |
646
- | [`examples/web/angular/ssr-examples/ssr-mixed/`](../../examples/web/angular/ssr-examples/ssr-mixed) | Mixed SSR/CSR routes — some routes server-rendered, others CSR-only |
647
- | [`examples/web/angular/ssr-examples/ssr-streaming/`](../../examples/web/angular/ssr-examples/ssr-streaming) | Streaming SSR with `@defer (on viewport)` + `@defer (on hover)` + `withIncrementalHydration()` |
648
- | [`examples/web/angular/ssr-examples/ssg/`](../../examples/web/angular/ssr-examples/ssg) | Static site generation via in-process AngularNodeAppEngine + `getStaticPaths()` |
643
+ | Example | Demonstrates |
644
+ | ----------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
645
+ | [`examples/web/angular/ssr-examples/ssr/`](../../examples/web/angular/ssr-examples/ssr) | Classical SSR with cookie-based DI, auth guards, nested loaders |
646
+ | [`examples/web/angular/ssr-examples/ssr-mixed/`](../../examples/web/angular/ssr-examples/ssr-mixed) | Mixed SSR/CSR routes — some routes server-rendered, others CSR-only |
647
+ | [`examples/web/angular/ssr-examples/ssr-streaming/`](../../examples/web/angular/ssr-examples/ssr-streaming) | Streaming SSR with `@defer (on viewport)` + `@defer (on hover)` + incremental hydration |
648
+ | [`examples/web/angular/ssr-examples/ssg/`](../../examples/web/angular/ssr-examples/ssg) | Static site generation via in-process AngularNodeAppEngine + `getStaticPaths()` |
649
649
 
650
650
  **Post-hydration loader skip (#599)** — `provideRealRouterFactory` automatically bridges Angular's `TransferState` to the cross-adapter hydration scratchpad. On the server pass, the resolved router state is written to `TransferState`; on the client, the bootstrap consumes the seed via `hydrateRouter(...)` and `ssr-data-plugin` reuses the server-resolved `state.context.data` without re-invoking the loader on first paint. Requires `provideServerRendering()` (server) + `provideClientHydration()` (client) — both standard for Angular SSR apps. Verified end-to-end in `ssr/` and `ssr-streaming/` examples via `window.__LOADER_CALLS__` counter assertion.
651
651
 
@@ -0,0 +1,2 @@
1
+ # Nested package.json's are only needed for development.
2
+ ssr/package.json
package/dist/README.md CHANGED
@@ -640,12 +640,12 @@ Existing `provideRealRouter(router)` is unchanged — keep using it for SPA / po
640
640
 
641
641
  **SSR / SSG examples** — `provideRealRouterFactory({ baseRouter, plugins, deps })`:
642
642
 
643
- | Example | Demonstrates |
644
- | ----------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
645
- | [`examples/web/angular/ssr-examples/ssr/`](../../examples/web/angular/ssr-examples/ssr) | Classical SSR with cookie-based DI, auth guards, nested loaders |
646
- | [`examples/web/angular/ssr-examples/ssr-mixed/`](../../examples/web/angular/ssr-examples/ssr-mixed) | Mixed SSR/CSR routes — some routes server-rendered, others CSR-only |
647
- | [`examples/web/angular/ssr-examples/ssr-streaming/`](../../examples/web/angular/ssr-examples/ssr-streaming) | Streaming SSR with `@defer (on viewport)` + `@defer (on hover)` + `withIncrementalHydration()` |
648
- | [`examples/web/angular/ssr-examples/ssg/`](../../examples/web/angular/ssr-examples/ssg) | Static site generation via in-process AngularNodeAppEngine + `getStaticPaths()` |
643
+ | Example | Demonstrates |
644
+ | ----------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
645
+ | [`examples/web/angular/ssr-examples/ssr/`](../../examples/web/angular/ssr-examples/ssr) | Classical SSR with cookie-based DI, auth guards, nested loaders |
646
+ | [`examples/web/angular/ssr-examples/ssr-mixed/`](../../examples/web/angular/ssr-examples/ssr-mixed) | Mixed SSR/CSR routes — some routes server-rendered, others CSR-only |
647
+ | [`examples/web/angular/ssr-examples/ssr-streaming/`](../../examples/web/angular/ssr-examples/ssr-streaming) | Streaming SSR with `@defer (on viewport)` + `@defer (on hover)` + incremental hydration |
648
+ | [`examples/web/angular/ssr-examples/ssg/`](../../examples/web/angular/ssr-examples/ssg) | Static site generation via in-process AngularNodeAppEngine + `getStaticPaths()` |
649
649
 
650
650
  **Post-hydration loader skip (#599)** — `provideRealRouterFactory` automatically bridges Angular's `TransferState` to the cross-adapter hydration scratchpad. On the server pass, the resolved router state is written to `TransferState`; on the client, the bootstrap consumes the seed via `hydrateRouter(...)` and `ssr-data-plugin` reuses the server-resolved `state.context.data` without re-invoking the loader on first paint. Requires `provideServerRendering()` (server) + `provideClientHydration()` (client) — both standard for Angular SSR apps. Verified end-to-end in `ssr/` and `ssr-streaming/` examples via `window.__LOADER_CALLS__` counter assertion.
651
651
 
@@ -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;
@@ -2009,8 +2068,8 @@ function provideRealRouterFactory(options) {
2009
2068
  //
2010
2069
  // 1. **Client after hydration** — server populated TransferState with
2011
2070
  // the SSR-resolved router state. Consume it via `hydrateRouter`,
2012
- // which deposits the parsed state into the one-shot
2013
- // `RouterInternals.hydrationState` scratchpad before invoking
2071
+ // which deposits the parsed state into `@real-router/ssr-utils`'
2072
+ // one-shot scratchpad before invoking
2014
2073
  // `router.start(state.path)`. SSR loader plugins
2015
2074
  // (`@real-router/ssr-data-plugin`, `@real-router/rsc-server-plugin`)
2016
2075
  // read the scratchpad and skip the loader on first paint — parity