@real-router/svelte 0.22.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.
@@ -1,17 +1,17 @@
1
1
  <script lang="ts">
2
2
  import { getNavigator } from "@real-router/core";
3
3
  import { createRouteSource, primeErrorSource } from "@real-router/sources";
4
+ import { setContext, untrack } from "svelte";
5
+
6
+ import { NAVIGATOR_KEY, ROUTE_KEY, ROUTER_KEY } from "./context";
7
+ import { createReactiveSource } from "./createReactiveSource.svelte";
8
+ import { createRouteContext } from "./createRouteContext.svelte";
4
9
  import {
5
10
  createRouteAnnouncer,
6
11
  createScrollRestoration,
7
12
  createScrollSpy,
8
13
  createViewTransitions,
9
14
  } from "./dom-utils";
10
- import { setContext, untrack } from "svelte";
11
-
12
- import { createReactiveSource } from "./createReactiveSource.svelte";
13
- import { createRouteContext } from "./createRouteContext.svelte";
14
- import { NAVIGATOR_KEY, ROUTE_KEY, ROUTER_KEY } from "./context";
15
15
 
16
16
  import type {
17
17
  RouteAnnouncerOptions,
@@ -54,13 +54,19 @@
54
54
  );
55
55
 
56
56
  $effect(() => {
57
- if (!anEnabled) return;
57
+ if (!anEnabled) {
58
+ return;
59
+ }
60
+
58
61
  void anPrefix;
59
62
  const options = untrack(() =>
60
63
  typeof announceNavigation === "object" ? announceNavigation : undefined,
61
64
  );
62
65
  const announcer = createRouteAnnouncer(router, options);
63
- return () => announcer.destroy();
66
+
67
+ return () => {
68
+ announcer.destroy();
69
+ };
64
70
  });
65
71
 
66
72
  // $derived memoizes by === so inline `{ mode: "restore" }` doesn't thrash:
@@ -73,7 +79,10 @@
73
79
  const srStorageKey = $derived(scrollRestoration?.storageKey);
74
80
 
75
81
  $effect(() => {
76
- if (!srEnabled) return;
82
+ if (!srEnabled) {
83
+ return;
84
+ }
85
+
77
86
  // Pin primitive $derived deps as explicit dependencies of this effect
78
87
  // BEFORE constructing the utility. The four `void srX` reads make
79
88
  // intent unambiguous: even if `createScrollRestoration` throws after
@@ -97,7 +106,10 @@
97
106
  storageKey: srStorageKey,
98
107
  scrollContainer: untrack(() => scrollRestoration?.scrollContainer),
99
108
  });
100
- return () => sr.destroy();
109
+
110
+ return () => {
111
+ sr.destroy();
112
+ };
101
113
  });
102
114
 
103
115
  const spyEnabled = $derived(
@@ -107,20 +119,32 @@
107
119
  const spyRootMargin = $derived(scrollSpy?.rootMargin);
108
120
 
109
121
  $effect(() => {
110
- if (!spyEnabled || !spySelector) return;
122
+ if (!spyEnabled || !spySelector) {
123
+ return;
124
+ }
125
+
111
126
  void spyRootMargin;
112
127
  const spy = createScrollSpy(router, {
113
128
  selector: spySelector,
114
129
  rootMargin: spyRootMargin,
115
130
  scrollContainer: untrack(() => scrollSpy?.scrollContainer),
116
131
  });
117
- return () => spy.destroy();
132
+
133
+ return () => {
134
+ spy.destroy();
135
+ };
118
136
  });
119
137
 
120
138
  $effect(() => {
121
- if (!viewTransitions) return;
139
+ if (!viewTransitions) {
140
+ return;
141
+ }
142
+
122
143
  const vt = createViewTransitions(router);
123
- return () => vt.destroy();
144
+
145
+ return () => {
146
+ vt.destroy();
147
+ };
124
148
  });
125
149
 
126
150
  // svelte-ignore state_referenced_locally
@@ -142,7 +166,6 @@
142
166
  // svelte-ignore state_referenced_locally
143
167
  // Context exposes the same stable router instance for this provider.
144
168
  setContext(ROUTER_KEY, router);
145
- // svelte-ignore state_referenced_locally
146
169
  // Context exposes the navigator derived once from the stable router.
147
170
  setContext(NAVIGATOR_KEY, navigator);
148
171
  setContext(ROUTE_KEY, routeContext);
@@ -1,5 +1,5 @@
1
- import type { ActionReturn } from "svelte/action";
2
1
  import type { Params, NavigationOptions } from "@real-router/core";
2
+ import type { ActionReturn } from "svelte/action";
3
3
  export interface LinkActionParams {
4
4
  name: string;
5
5
  params?: Params;
@@ -1,14 +1,14 @@
1
- import { ROUTER_KEY, getContextOrThrow } from "../context";
2
1
  import { EMPTY_OPTIONS, EMPTY_PARAMS, NOOP } from "../constants";
2
+ import { ROUTER_KEY, getContextOrThrow } from "../context";
3
3
  import { shouldNavigate, anchorTargetsAnotherContext, applyLinkA11y, } from "../dom-utils";
4
4
  const delegationByRouter = new WeakMap();
5
5
  function findRegisteredNode(nodes, target) {
6
- let el = target instanceof HTMLElement ? target : null;
7
- while (el) {
8
- if (nodes.has(el)) {
9
- return el;
6
+ let element = target instanceof HTMLElement ? target : null;
7
+ while (element) {
8
+ if (nodes.has(element)) {
9
+ return element;
10
10
  }
11
- el = el.parentElement;
11
+ element = element.parentElement;
12
12
  }
13
13
  return undefined;
14
14
  }
@@ -41,6 +41,7 @@ function getDelegation(router) {
41
41
  return;
42
42
  }
43
43
  evt.preventDefault();
44
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- findRegisteredNode returns only a node the map holds
44
45
  navigate(nodes.get(node));
45
46
  }
46
47
  function handleKeyDown(evt) {
@@ -59,6 +60,7 @@ function getDelegation(router) {
59
60
  if (anchorTargetsAnotherContext(node)) {
60
61
  return;
61
62
  }
63
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- findRegisteredNode returns only a node the map holds
62
64
  navigate(nodes.get(node));
63
65
  }
64
66
  const state = {
@@ -36,6 +36,7 @@
36
36
  // `useDeferred(name)` reads `state.context.ssrDataDeferred[name]` —
37
37
  // wrap in `$derived` so a dynamic `name` prop re-resolves the promise
38
38
  // (vs. capturing the initial value at component init).
39
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments -- `T` is this component's generic; without it the promise is `Promise<unknown>` and svelte-check fails
39
40
  const promise = $derived(useDeferred<T>(name));
40
41
  </script>
41
42
 
@@ -8,6 +8,7 @@
8
8
 
9
9
  let { children, fallback }: Props = $props();
10
10
 
11
+ // eslint-disable-next-line svelte/prefer-writable-derived -- `$effect` runs only in the browser after mount; a `$derived` would be true on the server too
11
12
  let mounted = $state(false);
12
13
 
13
14
  $effect(() => {
@@ -54,6 +54,7 @@
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
57
58
  // svelte-ignore state_referenced_locally
58
59
  // Intentional one-time read at component init: the sink is read by the
59
60
  // server after `await render()` and a single value is the contract.
@@ -28,27 +28,36 @@
28
28
  // invoking the loader synchronously on mount (throw-isolation class, #806).
29
29
  let pending: Promise<{ default: Component }>;
30
30
 
31
+ // eslint-disable-next-line sonarjs/no-try-promise -- the try catches a loader that throws before it returns a promise, as the comment above says
31
32
  try {
32
33
  pending = loader();
33
- } catch (err) {
34
- pending = Promise.reject(err);
34
+ } catch (error) {
35
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- the `.catch` below wraps a non-Error reason in an Error
36
+ pending = Promise.reject(error);
35
37
  }
36
38
 
37
39
  pending
38
40
  .then((module) => {
39
- if (!active) return;
40
- if (!module || typeof module.default === "undefined") {
41
+ if (!active) {
42
+ return;
43
+ }
44
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- a loader outside its type can resolve to anything
45
+ if (typeof module?.default === "undefined") {
41
46
  throw new Error(
42
47
  "[real-router] Lazy loader resolved without a `default` export.",
43
48
  );
44
49
  }
50
+
45
51
  state = { status: "ready", component: module.default };
46
52
  })
47
- .catch((err: unknown) => {
48
- if (!active) return;
53
+ .catch((error: unknown) => {
54
+ if (!active) {
55
+ return;
56
+ }
57
+
49
58
  state = {
50
59
  status: "error",
51
- error: err instanceof Error ? err : new Error(String(err)),
60
+ error: error instanceof Error ? error : new Error(String(error)),
52
61
  };
53
62
  });
54
63
 
@@ -25,16 +25,17 @@
25
25
  routeSearch,
26
26
  to,
27
27
  routeOptions = EMPTY_OPTIONS,
28
- class: className = undefined,
28
+ class: className,
29
29
  activeClassName = "active",
30
30
  activeStrict = false,
31
31
  ignoreQueryParams = true,
32
- hash = undefined,
33
- target = undefined,
34
- children = undefined,
35
- onclick: userOnClick = undefined,
32
+ hash,
33
+ target,
34
+ children,
35
+ onclick: userOnClick,
36
36
  ...restProps
37
37
  }: {
38
+ [key: string]: unknown;
38
39
  routeName?: string;
39
40
  routeParams?: Params;
40
41
  routeSearch?: SearchParams;
@@ -54,7 +55,6 @@
54
55
  target?: string;
55
56
  children?: Snippet;
56
57
  onclick?: (evt: MouseEvent) => void;
57
- [key: string]: unknown;
58
58
  } = $props();
59
59
 
60
60
  const router = useRouter();
@@ -1,6 +1,7 @@
1
1
  import type { NavigationOptions, NavigationTarget, Params, SearchParams } from "@real-router/core";
2
2
  import type { Snippet } from "svelte";
3
3
  type $$ComponentProps = {
4
+ [key: string]: unknown;
4
5
  routeName?: string;
5
6
  routeParams?: Params;
6
7
  routeSearch?: SearchParams;
@@ -20,7 +21,6 @@ type $$ComponentProps = {
20
21
  target?: string;
21
22
  children?: Snippet;
22
23
  onclick?: (evt: MouseEvent) => void;
23
- [key: string]: unknown;
24
24
  };
25
25
  declare const Link: import("svelte").Component<$$ComponentProps, {}, "">;
26
26
  type Link = ReturnType<typeof Link>;
@@ -1,8 +1,8 @@
1
1
  <script lang="ts">
2
2
  import { UNKNOWN_ROUTE } from "@real-router/core";
3
3
 
4
- import { useRouteNode } from "../composables/useRouteNode.svelte";
5
4
  import { getActiveSegment } from "./RouteView.helpers";
5
+ import { useRouteNode } from "../composables/useRouteNode.svelte";
6
6
 
7
7
  import type { Snippet } from "svelte";
8
8
 
@@ -12,10 +12,10 @@
12
12
  notFound,
13
13
  ...segmentSnippets
14
14
  }: {
15
+ [key: string]: Snippet | string | undefined;
15
16
  nodeName: string;
16
17
  self?: Snippet;
17
18
  notFound?: Snippet;
18
- [key: string]: Snippet | string | undefined;
19
19
  } = $props();
20
20
 
21
21
  // svelte-ignore state_referenced_locally
@@ -1,9 +1,9 @@
1
1
  import type { Snippet } from "svelte";
2
2
  type $$ComponentProps = {
3
+ [key: string]: Snippet | string | undefined;
3
4
  nodeName: string;
4
5
  self?: Snippet;
5
6
  notFound?: Snippet;
6
- [key: string]: Snippet | string | undefined;
7
7
  };
8
8
  declare const RouteView: import("svelte").Component<$$ComponentProps, {}, "">;
9
9
  type RouteView = ReturnType<typeof RouteView>;
@@ -25,9 +25,15 @@
25
25
 
26
26
  $effect(() => {
27
27
  const snap = snapshot.current;
28
- if (!snap.error) return;
28
+
29
+ if (!snap.error) {
30
+
31
+ return;
32
+
33
+ }
29
34
 
30
35
  const { error, toRoute, fromRoute } = snap;
36
+
31
37
  untrack(() => {
32
38
  try {
33
39
  onError?.(error, toRoute, fromRoute);
@@ -41,6 +47,7 @@
41
47
  });
42
48
  </script>
43
49
 
50
+ <!-- eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- `children` is typed as required; a consumer outside the type renders nothing rather than throwing -->
44
51
  {@render children?.()}
45
52
  {#if snapshot.current.error}
46
53
  {@render fallback(snapshot.current.error, snapshot.current.resetError)}
@@ -8,6 +8,7 @@
8
8
 
9
9
  let { children, fallback }: Props = $props();
10
10
 
11
+ // eslint-disable-next-line svelte/prefer-writable-derived -- `$effect` runs only in the browser after mount; a `$derived` would be true on the server too
11
12
  let mounted = $state(false);
12
13
 
13
14
  $effect(() => {
@@ -1,5 +1,5 @@
1
- import type { Navigator, State } from "@real-router/core";
2
1
  import type { RouteContext } from "./types";
2
+ import type { Navigator, State } from "@real-router/core";
3
3
  export interface RouteSnapshot {
4
4
  readonly route: State | undefined;
5
5
  readonly previousRoute: State | undefined;
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@real-router/svelte",
3
- "version": "0.22.0",
3
+ "version": "0.22.1",
4
4
  "type": "module",
5
5
  "description": "Svelte 5 integration for Real-Router",
6
6
  "svelte": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
+ "@real-router/internal-source": "./src/index.ts",
10
11
  "types": "./dist/index.d.ts",
11
12
  "svelte": "./dist/index.js",
12
13
  "default": "./dist/index.js"
13
14
  },
14
15
  "./ssr": {
16
+ "@real-router/internal-source": "./src/ssr.ts",
15
17
  "types": "./dist/ssr.d.ts",
16
18
  "svelte": "./dist/ssr.js",
17
19
  "default": "./dist/ssr.js"
@@ -53,20 +55,20 @@
53
55
  },
54
56
  "devDependencies": {
55
57
  "@real-router/browser-plugin": "^0.25.0",
56
- "@real-router/core": "^0.135.0",
58
+ "@real-router/core": "^0.147.8",
57
59
  "@sveltejs/package": "2.5.8",
58
60
  "@sveltejs/vite-plugin-svelte": "7.3.0",
59
- "@testing-library/jest-dom": "~6.9.1",
61
+ "@testing-library/jest-dom": "~7.0.1",
60
62
  "@testing-library/svelte": "~5.4.2",
61
63
  "@testing-library/user-event": "~14.6.1",
62
- "eslint-plugin-svelte": "3.19.0",
64
+ "eslint-plugin-svelte": "3.23.0",
63
65
  "rimraf": "6.1.3",
64
66
  "svelte": "~5.57.0",
65
67
  "svelte-check": "4.7.6",
66
- "svelte-eslint-parser": "1.8.0"
68
+ "svelte-eslint-parser": "1.8.1"
67
69
  },
68
70
  "peerDependencies": {
69
- "@real-router/core": ">=0.135.0",
71
+ "@real-router/core": ">=0.147.0",
70
72
  "svelte": ">=5.7.0"
71
73
  },
72
74
  "scripts": {