@real-router/svelte 0.24.0 → 0.24.2

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 CHANGED
@@ -317,7 +317,7 @@ Paired SSR-aware boundaries. `<ClientOnly>` renders the `fallback` snippet on th
317
317
 
318
318
  ```svelte
319
319
  <script lang="ts">
320
- import { ClientOnly, ServerOnly } from "@real-router/svelte";
320
+ import { ClientOnly, ServerOnly } from "@real-router/svelte/ssr";
321
321
  </script>
322
322
 
323
323
  <ClientOnly>
@@ -48,7 +48,31 @@ export function createDirectionTracker(router) {
48
48
  // in-flight transition and replays it from that transition's `finally`. The
49
49
  // gap has no upper bound. Measured on the obvious choice: a task-boundary
50
50
  // expiry disarms a live navigation on ONE async `canDeactivate`.
51
+ // ⚑ A traversal onto the URL of the router's own state starts no
52
+ // transition: a URL plugin's return after a refused Back or Forward
53
+ // (#2740), or a Back onto an entry holding that state. The URL comes from
54
+ // the URL plugin's `buildUrl`; without one, every popstate arms the flag.
55
+ const landsOnRouterState = () => {
56
+ const state = router.getState();
57
+ const buildUrl = router.buildUrl;
58
+ if (state === undefined || buildUrl === undefined) {
59
+ return false;
60
+ }
61
+ try {
62
+ const hash = state.context
63
+ ?.url?.hash;
64
+ const url = buildUrl(state.name, state.params, state.search, hash ? { hash } : undefined);
65
+ return (url !== undefined &&
66
+ new URL(url, globalThis.location.href).href === globalThis.location.href);
67
+ }
68
+ catch {
69
+ return false;
70
+ }
71
+ };
51
72
  const onPopstate = () => {
73
+ if (landsOnRouterState()) {
74
+ return;
75
+ }
52
76
  popstateFlag = true;
53
77
  // A deferred event belongs to the replay, not to the transition running
54
78
  // now, so that transition's terminal event must not spend it.
@@ -174,6 +174,11 @@ export function anchorTargetsAnotherContext(element) {
174
174
  function encodeFragmentInline(decoded) {
175
175
  return encodeURI(decoded).replaceAll("#", "%23");
176
176
  }
177
+ // A router path whose leading `/` is followed by `/` or `\` names a host, and
178
+ // `/.` keeps it a path on the page's origin. A copy of `HOST_PREFIX` in
179
+ // `shared/browser-env/url-utils.ts`: the dom-utils symlink graph does not reach
180
+ // browser-env.
181
+ const HOST_PREFIX = /^\/[\t\n\r]*[/\\]/;
177
182
  /**
178
183
  * Builds an href for a `<Link>` element.
179
184
  *
@@ -286,7 +291,8 @@ export function buildHref(router, routeName, routeParams, routeSearch, hash) {
286
291
  console.error(`[real-router] Route "${routeName}" yielded an empty path. The element will render without an href attribute.`);
287
292
  return undefined;
288
293
  }
289
- return normHash ? `${path}#${encodeFragmentInline(normHash)}` : path;
294
+ const href = HOST_PREFIX.test(path) ? `/.${path}` : path;
295
+ return normHash ? `${href}#${encodeFragmentInline(normHash)}` : href;
290
296
  }
291
297
  catch {
292
298
  console.error(`[real-router] Route "${routeName}" is not defined. The element will render without an href attribute.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@real-router/svelte",
3
- "version": "0.24.0",
3
+ "version": "0.24.2",
4
4
  "type": "module",
5
5
  "description": "Svelte 5 integration for Real-Router",
6
6
  "svelte": "./dist/index.js",
@@ -54,10 +54,10 @@
54
54
  "@real-router/sources": "^0.15.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@real-router/browser-plugin": "^0.25.0",
58
- "@real-router/core": "^0.148.0",
57
+ "@real-router/browser-plugin": "^0.26.2",
58
+ "@real-router/core": "^0.148.1",
59
59
  "@sveltejs/package": "2.5.8",
60
- "@sveltejs/vite-plugin-svelte": "7.3.0",
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
63
  "@testing-library/user-event": "~14.6.1",
@@ -66,7 +66,7 @@
66
66
  "svelte-check": "4.7.6"
67
67
  },
68
68
  "peerDependencies": {
69
- "@real-router/core": ">=0.148.0",
69
+ "@real-router/core": ">=0.148.1",
70
70
  "svelte": ">=5.7.0"
71
71
  },
72
72
  "scripts": {