@real-router/svelte 0.24.8 → 0.25.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 +7 -6
- package/dist/components/HttpStatusCode.svelte +0 -1
- package/dist/components/RouteView.svelte +1 -1
- package/dist/dom-utils/link-utils.d.ts +7 -6
- package/dist/dom-utils/link-utils.js +88 -18
- package/dist/dom-utils/scroll-restore.js +1 -0
- package/dist/types.d.ts +4 -3
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -553,12 +553,13 @@ Full documentation: [Wiki](https://github.com/greydragon888/real-router/wiki)
|
|
|
553
553
|
|
|
554
554
|
## Related Packages
|
|
555
555
|
|
|
556
|
-
| Package | Description
|
|
557
|
-
| ---------------------------------------------------------------------------------------- |
|
|
558
|
-
| [@real-router/core](https://www.npmjs.com/package/@real-router/core) | Core router (required peer dependency)
|
|
559
|
-
| [@real-router/browser-plugin](https://www.npmjs.com/package/@real-router/browser-plugin) | Browser History API integration
|
|
560
|
-
| [@real-router/sources](https://www.npmjs.com/package/@real-router/sources) | Subscription layer (used internally)
|
|
561
|
-
| [@real-router/route-utils](https://www.npmjs.com/package/@real-router/route-utils) | Route tree queries (`useRouteUtils`)
|
|
556
|
+
| Package | Description |
|
|
557
|
+
| ---------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
|
|
558
|
+
| [@real-router/core](https://www.npmjs.com/package/@real-router/core) | Core router (required peer dependency) |
|
|
559
|
+
| [@real-router/browser-plugin](https://www.npmjs.com/package/@real-router/browser-plugin) | Browser History API integration |
|
|
560
|
+
| [@real-router/sources](https://www.npmjs.com/package/@real-router/sources) | Subscription layer (used internally) |
|
|
561
|
+
| [@real-router/route-utils](https://www.npmjs.com/package/@real-router/route-utils) | Route tree queries (`useRouteUtils`) |
|
|
562
|
+
| [@real-router/ssr-utils](https://www.npmjs.com/package/@real-router/ssr-utils) | SSR helpers: serialize, hydrate, request scope, loader errors |
|
|
562
563
|
|
|
563
564
|
## Contributing
|
|
564
565
|
|
|
@@ -54,7 +54,6 @@
|
|
|
54
54
|
const sink = getContext<HttpStatusSink | undefined>(HTTP_STATUS_KEY);
|
|
55
55
|
|
|
56
56
|
if (sink) {
|
|
57
|
-
// eslint-disable-next-line svelte/no-unused-svelte-ignore -- svelte-check reports `state_referenced_locally` on `code` without it
|
|
58
57
|
// svelte-ignore state_referenced_locally
|
|
59
58
|
// Intentional one-time read at component init: the sink is read by the
|
|
60
59
|
// server after `await render()` and a single value is the contract.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { UNKNOWN_ROUTE } from "@real-router/core";
|
|
3
3
|
|
|
4
|
-
import { getActiveSegment } from "./RouteView.helpers";
|
|
5
4
|
import { useRouteNode } from "../composables/useRouteNode.svelte";
|
|
5
|
+
import { getActiveSegment } from "./RouteView.helpers";
|
|
6
6
|
|
|
7
7
|
import type { Snippet } from "svelte";
|
|
8
8
|
|
|
@@ -91,12 +91,13 @@ export declare function buildHref(router: Router, routeName: string, routeParams
|
|
|
91
91
|
* `<Link>` click-handler navigation helper (#532).
|
|
92
92
|
*
|
|
93
93
|
* Wraps `router.navigate(name, params, search, opts)` — the query channel took
|
|
94
|
-
* slot 3 in RFC-4 M2 (#1548) — with same-
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* SAME_STATES
|
|
98
|
-
*
|
|
99
|
-
*
|
|
94
|
+
* slot 3 in RFC-4 M2 (#1548) — with same-page different-hash detection. A
|
|
95
|
+
* hash-bearing Link that asks for a different fragment gets `force: true` and
|
|
96
|
+
* `hashChange: true` in two cases: its values match the page, or core would
|
|
97
|
+
* refuse it as `SAME_STATES` because it builds the committed path with other
|
|
98
|
+
* values — then the page itself is re-committed. `printsPath` and the path arm
|
|
99
|
+
* name the exceptions to the second case. Subscribers can then disambiguate
|
|
100
|
+
* via `state.context.url.hashChanged`.
|
|
100
101
|
*
|
|
101
102
|
* For pure programmatic same-route hash-only navigation, callers are
|
|
102
103
|
* documented to pass `{ force: true }` themselves; the auto-bypass here is
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UNKNOWN_ROUTE } from "@real-router/core";
|
|
1
2
|
import { getPluginApi } from "@real-router/core/api";
|
|
2
3
|
import { putField } from "@real-router/core/utils";
|
|
3
4
|
/**
|
|
@@ -14,6 +15,7 @@ import { putField } from "@real-router/core/utils";
|
|
|
14
15
|
* (#1798), which is the doctrine's own caveat and travels with it.
|
|
15
16
|
*/
|
|
16
17
|
const objectKeys = Object.keys;
|
|
18
|
+
const hasOwn = Object.hasOwn;
|
|
17
19
|
/**
|
|
18
20
|
* The brand `packages/core/src/internals.ts` puts on every router it registers,
|
|
19
21
|
* RE-DECLARED rather than imported (#2294).
|
|
@@ -299,16 +301,62 @@ export function buildHref(router, routeName, routeParams, routeSearch, hash) {
|
|
|
299
301
|
return undefined;
|
|
300
302
|
}
|
|
301
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* Does `(routeName, routeParams, routeSearch)` print `path` through the
|
|
306
|
+
* resolving door `buildHref` renders (#2250)? `forwardState` resolves the
|
|
307
|
+
* chain — `forwardTo` and the interceptors plugins register on it — and
|
|
308
|
+
* `buildPathResolved` prints the target: for a link `navigate` accepts, the
|
|
309
|
+
* path core compares with the committed one.
|
|
310
|
+
*
|
|
311
|
+
* ⚠ No literal fallback: `router.buildPath` does not follow `forwardTo`, so it
|
|
312
|
+
* is not the path `navigate` builds.
|
|
313
|
+
*
|
|
314
|
+
* A router `getPluginApi` refuses — a test double, a `Proxy` wrapper — answers
|
|
315
|
+
* "no", as does a print that throws; the caller then navigates as the link
|
|
316
|
+
* wrote it.
|
|
317
|
+
*/
|
|
318
|
+
function printsPath(router, routeName, routeParams, routeSearch, path) {
|
|
319
|
+
try {
|
|
320
|
+
const api = getPluginApi(router);
|
|
321
|
+
const forwarded = api.forwardState(routeName, routeParams, routeSearch);
|
|
322
|
+
return (api.buildPathResolved(forwarded.name, forwarded.params, forwarded.search) === path);
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* The bypass both arms of `navigateWithHash` add. `putField`, as for the
|
|
330
|
+
* fragment slot there (#2141): the spread `opts` has no own key for either flag
|
|
331
|
+
* unless the caller's extra options carried one, so a plain assignment would
|
|
332
|
+
* reach an ambient accessor on `Object.prototype`.
|
|
333
|
+
*/
|
|
334
|
+
function addBypass(opts) {
|
|
335
|
+
const slots = opts;
|
|
336
|
+
putField(slots, "force", true);
|
|
337
|
+
putField(slots, "hashChange", true);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Whether the caller's own options already take the navigation past
|
|
341
|
+
* `SAME_STATES`: core reads `reload` and `force` as own keys of its copy of
|
|
342
|
+
* the options, by truth (`isSameNavigation`). The spread `opts` holds the
|
|
343
|
+
* caller's own enumerable keys as data, so reading it runs no caller code.
|
|
344
|
+
*/
|
|
345
|
+
function callerBypasses(opts) {
|
|
346
|
+
return ((hasOwn(opts, "reload") && Boolean(opts.reload)) ||
|
|
347
|
+
(hasOwn(opts, "force") && Boolean(opts.force)));
|
|
348
|
+
}
|
|
302
349
|
/**
|
|
303
350
|
* `<Link>` click-handler navigation helper (#532).
|
|
304
351
|
*
|
|
305
352
|
* Wraps `router.navigate(name, params, search, opts)` — the query channel took
|
|
306
|
-
* slot 3 in RFC-4 M2 (#1548) — with same-
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* SAME_STATES
|
|
310
|
-
*
|
|
311
|
-
*
|
|
353
|
+
* slot 3 in RFC-4 M2 (#1548) — with same-page different-hash detection. A
|
|
354
|
+
* hash-bearing Link that asks for a different fragment gets `force: true` and
|
|
355
|
+
* `hashChange: true` in two cases: its values match the page, or core would
|
|
356
|
+
* refuse it as `SAME_STATES` because it builds the committed path with other
|
|
357
|
+
* values — then the page itself is re-committed. `printsPath` and the path arm
|
|
358
|
+
* name the exceptions to the second case. Subscribers can then disambiguate
|
|
359
|
+
* via `state.context.url.hashChanged`.
|
|
312
360
|
*
|
|
313
361
|
* For pure programmatic same-route hash-only navigation, callers are
|
|
314
362
|
* documented to pass `{ force: true }` themselves; the auto-bypass here is
|
|
@@ -355,18 +403,18 @@ export function navigateWithHash(router, routeName, routeParams, routeSearch, ha
|
|
|
355
403
|
// (#1548) — the predicate applies the channel rule instead of re-deriving
|
|
356
404
|
// it.
|
|
357
405
|
//
|
|
358
|
-
// `strictEquality: true` —
|
|
359
|
-
//
|
|
360
|
-
// false` — the query is part of
|
|
361
|
-
// the
|
|
362
|
-
// through as a hash change.
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
opts
|
|
406
|
+
// `strictEquality: true` — the hierarchical arm would match a parent route
|
|
407
|
+
// on a child page at another URL, and the bypass would announce that move
|
|
408
|
+
// as a fragment change. `ignoreQueryParams: false` — the query is part of
|
|
409
|
+
// the location here; ignoring it would fire the bypass across a real query
|
|
410
|
+
// change and let `force: true` smuggle it through as a hash change.
|
|
411
|
+
const sameValues = router.isActiveRoute(routeName, routeParams, sameLocationSearch, true, false);
|
|
412
|
+
const currentHash = current.context?.url?.hash ??
|
|
413
|
+
"";
|
|
414
|
+
const newHash = hash ?? currentHash;
|
|
415
|
+
if (currentHash !== newHash) {
|
|
416
|
+
if (sameValues) {
|
|
417
|
+
addBypass(opts);
|
|
370
418
|
// Reaching here means the predicate answered "this is where we already
|
|
371
419
|
// are, only the fragment differs", and `force` + `hashChange` announce
|
|
372
420
|
// exactly that. The bare `routeSearch` would say "no query" rather than
|
|
@@ -382,6 +430,28 @@ export function navigateWithHash(router, routeName, routeParams, routeSearch, ha
|
|
|
382
430
|
// the #1925 suite.
|
|
383
431
|
navigatedSearch = sameLocationSearch;
|
|
384
432
|
}
|
|
433
|
+
else if (!callerBypasses(opts) &&
|
|
434
|
+
current.name !== UNKNOWN_ROUTE &&
|
|
435
|
+
printsPath(router, routeName, routeParams, routeSearch, current.path)) {
|
|
436
|
+
// `sameValues` misses part of what core refuses: core refuses a
|
|
437
|
+
// navigation with neither `reload` nor `force` truthy in its options
|
|
438
|
+
// that builds the path the router shows (`isSameNavigation`), and a
|
|
439
|
+
// link can build that path with other values — for example one that
|
|
440
|
+
// prints no key (`[]`, `null` under `nullFormat: "hidden"`), a key an
|
|
441
|
+
// interceptor adds, the parent of an index route at the same URL
|
|
442
|
+
// (#3040). Such a link points at this page, so the page is
|
|
443
|
+
// re-committed with the new fragment: the route, params and query the
|
|
444
|
+
// router shows. The link's own values could commit a state the URL
|
|
445
|
+
// does not show — `{ tags: [] }` behind `/products` — and run guards
|
|
446
|
+
// on a fragment click: an empty value re-enters the route, the parent
|
|
447
|
+
// of an index route leaves its child.
|
|
448
|
+
//
|
|
449
|
+
// ⚠ A 404 page is not re-committed: `navigate` cannot target
|
|
450
|
+
// `UNKNOWN_ROUTE`, so a link that prints its URL stays refused as
|
|
451
|
+
// `SAME_STATES`.
|
|
452
|
+
addBypass(opts);
|
|
453
|
+
return router.navigate(current.name, current.params, current.search, opts);
|
|
454
|
+
}
|
|
385
455
|
}
|
|
386
456
|
}
|
|
387
457
|
// Query channel at position 3 (RFC-4 M2 / #1548); opts at position 4.
|
|
@@ -100,6 +100,7 @@ export function createScrollRestoration(router, options) {
|
|
|
100
100
|
const element = getContainer?.();
|
|
101
101
|
return element ? element.scrollTop : globalThis.scrollY;
|
|
102
102
|
};
|
|
103
|
+
// eslint-disable-next-line unicorn/no-unnecessary-parameters -- a position writer; every caller resets to the top
|
|
103
104
|
const writePos = (top) => {
|
|
104
105
|
const element = getContainer?.();
|
|
105
106
|
if (element) {
|
package/dist/types.d.ts
CHANGED
|
@@ -49,9 +49,10 @@ export interface LinkProps<P extends Params = Params> {
|
|
|
49
49
|
* URL fragment (decoded, no leading "#") — #532.
|
|
50
50
|
* - `undefined` → preserve current `state.context.url.hash` on click.
|
|
51
51
|
* - `""` → clear the hash.
|
|
52
|
-
* - `"value"` → set the hash;
|
|
53
|
-
*
|
|
54
|
-
*
|
|
52
|
+
* - `"value"` → set the hash; clicks route through `navigateWithHash`, which
|
|
53
|
+
* adds `force: true, hashChange: true` when the link points at the page the
|
|
54
|
+
* router shows and asks for another fragment (bypasses core's SAME_STATES
|
|
55
|
+
* check — the Hash wiki page has the details).
|
|
55
56
|
*/
|
|
56
57
|
readonly hash?: string;
|
|
57
58
|
readonly target?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@real-router/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Svelte 5 integration for Real-Router",
|
|
6
6
|
"svelte": "./dist/index.js",
|
|
@@ -54,19 +54,19 @@
|
|
|
54
54
|
"@real-router/sources": "^0.17.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@real-router/browser-plugin": "^0.28.
|
|
58
|
-
"@real-router/core": "^0.
|
|
57
|
+
"@real-router/browser-plugin": "^0.28.1",
|
|
58
|
+
"@real-router/core": "^0.173.2",
|
|
59
59
|
"@sveltejs/package": "2.5.8",
|
|
60
60
|
"@sveltejs/vite-plugin-svelte": "7.3.1",
|
|
61
61
|
"@testing-library/jest-dom": "~7.0.1",
|
|
62
62
|
"@testing-library/svelte": "~5.4.2",
|
|
63
|
-
"@testing-library/user-event": "~14.6.
|
|
63
|
+
"@testing-library/user-event": "~14.6.14",
|
|
64
64
|
"rimraf": "6.1.3",
|
|
65
|
-
"svelte": "~5.
|
|
66
|
-
"svelte-check": "4.7.
|
|
65
|
+
"svelte": "~5.59.1",
|
|
66
|
+
"svelte-check": "4.7.9"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@real-router/core": ">=0.
|
|
69
|
+
"@real-router/core": ">=0.173.2",
|
|
70
70
|
"svelte": ">=5.7.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|