@real-router/svelte 0.24.1 → 0.24.3

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.
@@ -32,7 +32,8 @@ export function createDirectionTracker(router) {
32
32
  }
33
33
  let popstateFlag = false;
34
34
  document.documentElement.dataset.navDirection = "forward";
35
- let transitionInFlight = false;
35
+ // The `toState` the transition in flight was announced with.
36
+ let inFlight;
36
37
  let armedMidTransition = false;
37
38
  // ⚑ The flag is SPENT by the transition it belongs to, whether or not that
38
39
  // transition reaches a leave phase (#1924). It is armed by any `popstate` on
@@ -76,7 +77,7 @@ export function createDirectionTracker(router) {
76
77
  popstateFlag = true;
77
78
  // A deferred event belongs to the replay, not to the transition running
78
79
  // now, so that transition's terminal event must not spend it.
79
- armedMidTransition = transitionInFlight;
80
+ armedMidTransition = inFlight !== undefined;
80
81
  };
81
82
  // IMPORTANT — listener-ordering: `popstate` fires on `window`, which
82
83
  // has no DOM descendants, so capture phase is moot. Listeners are
@@ -88,19 +89,37 @@ export function createDirectionTracker(router) {
88
89
  globalThis.addEventListener("popstate", onPopstate);
89
90
  const api = getPluginApi(router);
90
91
  const onSettled = () => {
91
- transitionInFlight = false;
92
+ inFlight = undefined;
92
93
  if (armedMidTransition) {
93
94
  armedMidTransition = false;
94
95
  return;
95
96
  }
96
97
  popstateFlag = false;
97
98
  };
99
+ // Core also reports a refusal that starts no transition on
100
+ // `TRANSITION_ERROR`, and may do so while another transition runs. A
101
+ // transition's own error carries a `toState` with that transition's
102
+ // `context`, so another one does not settle it (#2779). With nothing in
103
+ // flight every error settles: the `SAME_STATES` arc above spends the flag
104
+ // that way.
105
+ const onError = (toState) => {
106
+ if (inFlight === undefined || toState?.context === inFlight.context) {
107
+ onSettled();
108
+ }
109
+ else {
110
+ // A popstate armed while the transition runs may be the one this
111
+ // refusal answers: a URL plugin handles a popstate that arrives during a
112
+ // programmatic transition on the spot. So that transition's terminal
113
+ // spends the flag instead of keeping it for a replay.
114
+ armedMidTransition = false;
115
+ }
116
+ };
98
117
  const unsubs = [
99
- api.addEventListener(events.TRANSITION_START, () => {
100
- transitionInFlight = true;
118
+ api.addEventListener(events.TRANSITION_START, (toState) => {
119
+ inFlight = toState;
101
120
  }),
102
121
  api.addEventListener(events.TRANSITION_SUCCESS, onSettled),
103
- api.addEventListener(events.TRANSITION_ERROR, onSettled),
122
+ api.addEventListener(events.TRANSITION_ERROR, onError),
104
123
  api.addEventListener(events.TRANSITION_CANCEL, onSettled),
105
124
  router.subscribeLeave(() => {
106
125
  document.documentElement.dataset.navDirection = popstateFlag
@@ -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.1",
3
+ "version": "0.24.3",
4
4
  "type": "module",
5
5
  "description": "Svelte 5 integration for Real-Router",
6
6
  "svelte": "./dist/index.js",
@@ -51,11 +51,11 @@
51
51
  "sideEffects": false,
52
52
  "dependencies": {
53
53
  "@real-router/route-utils": "^0.4.0",
54
- "@real-router/sources": "^0.15.0"
54
+ "@real-router/sources": "^0.15.1"
55
55
  },
56
56
  "devDependencies": {
57
- "@real-router/browser-plugin": "^0.26.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
60
  "@sveltejs/vite-plugin-svelte": "7.3.1",
61
61
  "@testing-library/jest-dom": "~7.0.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": {