@real-router/svelte 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.
@@ -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:
@@ -164,14 +215,19 @@ export function buildHref(router, routeName, routeParams, routeSearch, hash) {
164
215
  // lands, and the click resolves `forwardTo`. `router.buildPath` alone is
165
216
  // class LITERAL by record and answers about the route it was NAMED —
166
217
  // INVARIANTS #8 keeps that so a plugin can build a state for an alias
167
- // without being teleported off it — so the chain is resolved FIRST and
168
- // `buildPath` prints the target. The door choice belongs here rather than
169
- // one layer down.
218
+ // without being teleported off it — so the chain is resolved FIRST and the
219
+ // printer prints the target. The door choice belongs here rather than one
220
+ // layer down.
170
221
  //
171
- // ⚠ The `??` preserves the FAILURE shape, it is not a convenience: a name the
172
- // table does not hold makes the class-① door answer `undefined` where
173
- // `buildPath` THROWS, and that throw is what `packages/react/INVARIANTS.md`
174
- // row 3 pins (`Both throw → undefined + console.error`).
222
+ // ⚠ **The `??` is not reached by a name the table does not hold, and the
223
+ // claim that it was described a door this arm stopped calling.** That read
224
+ // `buildNavigationState`, which answers `undefined` for an unknown route;
225
+ // since #2265 the resolving door is `forwardState`, which ANSWERS for one
226
+ // (measured — it does not validate the name), leaving the printer to throw.
227
+ // `packages/react/INVARIANTS.md` row 3 still holds — `Both throw →
228
+ // undefined + console.error` — but it is reached by both printers throwing,
229
+ // not by a `undefined` the `??` absorbs. What the `??` IS load-bearing for
230
+ // is the two cases below.
175
231
  //
176
232
  // ⚠ **The fallback is also where the channel guard lands (#1572).** A route's
177
233
  // declared query name handed in the PATH bag makes the class-① door throw
@@ -187,14 +243,34 @@ export function buildHref(router, routeName, routeParams, routeSearch, hash) {
187
243
  // `packages/react/tests/functional/dom-utils/forwarding-link-href-2250.test.ts`
188
244
  // owns that.
189
245
  let resolved;
246
+ const api = readPluginApi(router, routeName);
190
247
  try {
191
248
  // ⚠ **`forwardState`, not `buildNavigationState`.** Both resolve the whole
192
249
  // chain, and the href is identical — but the committing door opts into
193
250
  // `reportUndeclaredParamKey`, and an href COMMITS NOTHING. That diagnostic
194
251
  // is for a state you are about to persist, which is why `canNavigateTo`
195
252
  // is silent despite sharing `navigate`'s form (#2248 / #1581).
196
- const forwarded = getPluginApi(router).forwardState(routeName, routeParams, routeSearch);
197
- resolved = router.buildPath(forwarded.name, forwarded.params, forwarded.search);
253
+ // ⚑ **`buildPathResolved`, not `router.buildPath` — ONE href is ONE pass
254
+ // of the chain (#2260).** The facade's printer runs the `forwardState`
255
+ // seam a door lower (#2087), which is right for a caller holding a raw
256
+ // intent and a SECOND pass for this one, which just resolved. Counted,
257
+ // because nothing in either door's source says "twice": the second pass
258
+ // is what two individually-correct doors compose to.
259
+ //
260
+ // ⚠ A plugin author registers one interceptor and has no reason to expect
261
+ // two invocations per href — a stateful one double-counts. Cost is the
262
+ // lesser half: +1333 ns per href with `search-schema` +
263
+ // `persistent-params` installed, per `<Link>` per render.
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);
198
274
  }
199
275
  catch {
200
276
  resolved = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real-router/svelte",
3
- "version": "0.20.2",
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.133.0",
52
51
  "@real-router/route-utils": "^0.4.0",
53
- "@real-router/sources": "^0.14.40"
52
+ "@real-router/sources": "^0.15.0"
54
53
  },
55
54
  "devDependencies": {
56
- "@real-router/browser-plugin": "^0.23.2",
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": {