@real-router/svelte 0.17.30 → 0.17.32
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.
|
@@ -71,15 +71,25 @@ export type RouteExitHandler = (context: RouteExitContext) => void | Promise<voi
|
|
|
71
71
|
* <div bind:this={el}>...</div>
|
|
72
72
|
* ```
|
|
73
73
|
*
|
|
74
|
-
* @example
|
|
74
|
+
* @example Detecting that you are leaving a subtree
|
|
75
75
|
* ```svelte
|
|
76
76
|
* <script lang="ts">
|
|
77
|
-
*
|
|
78
|
-
*
|
|
77
|
+
* const inProducts = (name: string) =>
|
|
78
|
+
* name === "products" || name.startsWith("products.");
|
|
79
|
+
*
|
|
80
|
+
* useRouteExit(({ route, nextRoute }) => {
|
|
81
|
+
* if (inProducts(route.name) && !inProducts(nextRoute.name)) {
|
|
79
82
|
* productCache.clear();
|
|
80
83
|
* }
|
|
81
84
|
* });
|
|
82
85
|
* </script>
|
|
83
86
|
* ```
|
|
87
|
+
*
|
|
88
|
+
* ⚠ Do NOT read `nextRoute.transition` here. `nextRoute` is the PENDING target,
|
|
89
|
+
* and the pipeline gives it the neutral default — empty `segments`, optional
|
|
90
|
+
* flags `undefined` — so the example this replaced read `[]` and `undefined`
|
|
91
|
+
* whatever the navigation was. (It threw outright until real-router#1976
|
|
92
|
+
* attached the field.) The real metadata is written at the COMMIT: read it in
|
|
93
|
+
* `router.subscribe`, `onTransitionSuccess`, or `getState()`.
|
|
84
94
|
*/
|
|
85
95
|
export declare function useRouteExit(handler: RouteExitHandler, options?: UseRouteExitOptions): void;
|
|
@@ -50,16 +50,26 @@ import { useRouter } from "./useRouter.svelte";
|
|
|
50
50
|
* <div bind:this={el}>...</div>
|
|
51
51
|
* ```
|
|
52
52
|
*
|
|
53
|
-
* @example
|
|
53
|
+
* @example Detecting that you are leaving a subtree
|
|
54
54
|
* ```svelte
|
|
55
55
|
* <script lang="ts">
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
* const inProducts = (name: string) =>
|
|
57
|
+
* name === "products" || name.startsWith("products.");
|
|
58
|
+
*
|
|
59
|
+
* useRouteExit(({ route, nextRoute }) => {
|
|
60
|
+
* if (inProducts(route.name) && !inProducts(nextRoute.name)) {
|
|
58
61
|
* productCache.clear();
|
|
59
62
|
* }
|
|
60
63
|
* });
|
|
61
64
|
* </script>
|
|
62
65
|
* ```
|
|
66
|
+
*
|
|
67
|
+
* ⚠ Do NOT read `nextRoute.transition` here. `nextRoute` is the PENDING target,
|
|
68
|
+
* and the pipeline gives it the neutral default — empty `segments`, optional
|
|
69
|
+
* flags `undefined` — so the example this replaced read `[]` and `undefined`
|
|
70
|
+
* whatever the navigation was. (It threw outright until real-router#1976
|
|
71
|
+
* attached the field.) The real metadata is written at the COMMIT: read it in
|
|
72
|
+
* `router.subscribe`, `onTransitionSuccess`, or `getState()`.
|
|
63
73
|
*/
|
|
64
74
|
export function useRouteExit(handler, options) {
|
|
65
75
|
const router = useRouter();
|
|
@@ -294,7 +294,12 @@ export function createScrollRestoration(router, options) {
|
|
|
294
294
|
// leaves opts.reload undefined, so dropping the plugin arm would regress F5
|
|
295
295
|
// scroll-restore. Browser-plugin's F5 is not covered (no priming, out of
|
|
296
296
|
// scope).
|
|
297
|
-
|
|
297
|
+
// `?.` on a required field: core commits a foreign State's ABSENT
|
|
298
|
+
// `transition` rather than fabricating one (#1792 / #1976), and this runs
|
|
299
|
+
// on whatever `subscribe` hands over. Absent falls through to the plugin
|
|
300
|
+
// arm, which is the pre-#1976 answer for a state carrying no meta.
|
|
301
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- the required field is genuinely absent on a foreign committed State
|
|
302
|
+
if (route.transition?.reload || nav?.navigationType === "reload") {
|
|
298
303
|
const key = safeKeyOf(route);
|
|
299
304
|
restorePos(key === null ? 0 : (loadStore()[key] ?? 0));
|
|
300
305
|
return;
|
|
@@ -305,7 +310,9 @@ export function createScrollRestoration(router, options) {
|
|
|
305
310
|
return;
|
|
306
311
|
}
|
|
307
312
|
// Genuine in-place replace (not a traversal) — leave scroll untouched.
|
|
308
|
-
|
|
313
|
+
// `?.` for the same reason as the reload arm above.
|
|
314
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- the required field is genuinely absent on a foreign committed State
|
|
315
|
+
if (route.transition?.replace || nav?.navigationType === "replace") {
|
|
309
316
|
return;
|
|
310
317
|
}
|
|
311
318
|
scrollToHashOrTop(route);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@real-router/svelte",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.32",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Svelte 5 integration for Real-Router",
|
|
6
6
|
"svelte": "./dist/index.js",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"sideEffects": false,
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@real-router/core": "^0.
|
|
51
|
+
"@real-router/core": "^0.111.0",
|
|
52
52
|
"@real-router/route-utils": "^0.3.0",
|
|
53
|
-
"@real-router/sources": "^0.14.
|
|
53
|
+
"@real-router/sources": "^0.14.14"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@sveltejs/package": "2.5.8",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"svelte": "~5.56.4",
|
|
64
64
|
"svelte-check": "4.6.0",
|
|
65
65
|
"svelte-eslint-parser": "1.8.0",
|
|
66
|
-
"@real-router/browser-plugin": "^0.21.
|
|
66
|
+
"@real-router/browser-plugin": "^0.21.14"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"svelte": ">=5.7.0"
|