@real-router/svelte 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.
@@ -14,6 +14,57 @@ import { putField } from "@real-router/core/utils";
14
14
  * (#1798), which is the doctrine's own caveat and travels with it.
15
15
  */
16
16
  const objectKeys = Object.keys;
17
+ /**
18
+ * The brand `packages/core/src/internals.ts` puts on every router it registers,
19
+ * RE-DECLARED rather than imported (#2294).
20
+ *
21
+ * ⚑ `Symbol.for` makes the two the same symbol, so **the STRING is the
22
+ * contract** — change it in one place and this warning silently stops firing.
23
+ * The same shape core already uses for `CONFIG_FAULT`, declared twice across a
24
+ * boundary it cannot import over, and pinned the same way: the guard is
25
+ * `foreign-router-href-2294.test.ts`, whose cells fail on exactly that drift.
26
+ */
27
+ const ROUTER_BRAND = Symbol.for("real-router.router");
28
+ /**
29
+ * Is this a real router that core cannot read — as opposed to the `Router`-SHAPED
30
+ * double this helper accepts by contract?
31
+ *
32
+ * ⚠ Read defensively: the argument is the caller's object and may be a `Proxy`
33
+ * whose `get` trap throws. A diagnostic that throws would change where the error
34
+ * comes FROM, which is the #1572 class, so a throwing read means "cannot tell".
35
+ */
36
+ function isUnreadableRouter(candidate) {
37
+ try {
38
+ return (candidate?.[ROUTER_BRAND] === true);
39
+ }
40
+ catch {
41
+ return false;
42
+ }
43
+ }
44
+ /**
45
+ * The registry lookup, ALONE — and standing alone is what makes the warning
46
+ * correct (#2294).
47
+ *
48
+ * ⚑ Inside the resolve-and-print `try` this could not be told apart from a
49
+ * `forwardState` that threw for a reason the arm handles deliberately. The
50
+ * channel guard (#1572) is exactly that, and it fires on a router that IS
51
+ * registered and IS branded — so a check made there would report duplicated core
52
+ * on a perfectly healthy one.
53
+ */
54
+ function readPluginApi(router, routeName) {
55
+ try {
56
+ return getPluginApi(router);
57
+ }
58
+ catch {
59
+ if (isUnreadableRouter(router)) {
60
+ console.error(`[real-router] Route "${routeName}" rendered its LITERAL path: this IS a router, ` +
61
+ "but not one this copy of @real-router/core built, so `forwardTo` was not resolved. " +
62
+ "It is either wrapped in a Proxy (Vue `reactive()` / Pinia — store it with `markRaw`), " +
63
+ "or your dependency tree holds two copies of @real-router/core — dedupe it to one.");
64
+ }
65
+ return undefined;
66
+ }
67
+ }
17
68
  /**
18
69
  * Collapses a `<Link>`'s two prop forms (RFC-4 M2 B2, #1548) into one channel
19
70
  * triple:
@@ -192,6 +243,7 @@ export function buildHref(router, routeName, routeParams, routeSearch, hash) {
192
243
  // `packages/react/tests/functional/dom-utils/forwarding-link-href-2250.test.ts`
193
244
  // owns that.
194
245
  let resolved;
246
+ const api = readPluginApi(router, routeName);
195
247
  try {
196
248
  // ⚠ **`forwardState`, not `buildNavigationState`.** Both resolve the whole
197
249
  // chain, and the href is identical — but the committing door opts into
@@ -209,9 +261,16 @@ export function buildHref(router, routeName, routeParams, routeSearch, hash) {
209
261
  // two invocations per href — a stateful one double-counts. Cost is the
210
262
  // lesser half: +1333 ns per href with `search-schema` +
211
263
  // `persistent-params` installed, per `<Link>` per render.
212
- const api = getPluginApi(router);
213
- const forwarded = api.forwardState(routeName, routeParams, routeSearch);
214
- resolved = api.buildPathResolved(forwarded.name, forwarded.params, forwarded.search);
264
+ //
265
+ // ⚠ `api?.` is a TYPE gate, not a runtime guard, and naming it so keeps it
266
+ // from being read as one: calling `forwardState` on `undefined` throws
267
+ // into the same `catch` for the same outcome, so a mutant dropping the
268
+ // check is EQUIVALENT. What it buys is that TypeScript can see the call is
269
+ // safe below a lookup that may have failed (#2294).
270
+ const forwarded = api?.forwardState(routeName, routeParams, routeSearch);
271
+ resolved =
272
+ forwarded &&
273
+ api?.buildPathResolved(forwarded.name, forwarded.params, forwarded.search);
215
274
  }
216
275
  catch {
217
276
  resolved = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real-router/svelte",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "type": "module",
5
5
  "description": "Svelte 5 integration for Real-Router",
6
6
  "svelte": "./dist/index.js",
@@ -48,12 +48,12 @@
48
48
  "license": "MIT",
49
49
  "sideEffects": false,
50
50
  "dependencies": {
51
- "@real-router/core": "^0.134.0",
52
51
  "@real-router/route-utils": "^0.4.0",
53
- "@real-router/sources": "^0.14.41"
52
+ "@real-router/sources": "^0.15.0"
54
53
  },
55
54
  "devDependencies": {
56
- "@real-router/browser-plugin": "^0.24.0",
55
+ "@real-router/browser-plugin": "^0.25.0",
56
+ "@real-router/core": "^0.135.0",
57
57
  "@sveltejs/package": "2.5.8",
58
58
  "@sveltejs/vite-plugin-svelte": "7.3.0",
59
59
  "@testing-library/jest-dom": "~6.9.1",
@@ -66,6 +66,7 @@
66
66
  "svelte-eslint-parser": "1.8.0"
67
67
  },
68
68
  "peerDependencies": {
69
+ "@real-router/core": ">=0.135.0",
69
70
  "svelte": ">=5.7.0"
70
71
  },
71
72
  "scripts": {