@teyik0/furin 0.2.0-alpha.5 → 0.4.0-alpha.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.
Files changed (282) hide show
  1. package/README.md +2 -3
  2. package/dist/adapter/bun.d.ts +1 -1
  3. package/dist/adapter/static.d.ts +1 -1
  4. package/dist/build/bun-build.d.ts +3 -0
  5. package/dist/build/client.d.ts +2 -2
  6. package/dist/build/entry-template.d.ts +6 -0
  7. package/dist/build/entry-template.ts +20 -3
  8. package/dist/build/hydrate.d.ts +1 -1
  9. package/dist/build/index.d.ts +1 -1
  10. package/dist/build/index.js +9363 -5827
  11. package/dist/build/production-instrumentation.d.ts +1 -0
  12. package/dist/build/route-types.d.ts +3 -23
  13. package/dist/build/shared.d.ts +1 -1
  14. package/dist/build/ssg-cache.d.ts +1 -1
  15. package/dist/build/types.d.ts +2 -1
  16. package/dist/cli/index.js +9467 -5870
  17. package/dist/client/boundaries.d.ts +6 -4
  18. package/dist/client/define-route.d.ts +35 -0
  19. package/dist/client/document.d.ts +26 -0
  20. package/dist/client/hmr.d.ts +10 -0
  21. package/dist/client/internal/runtime-types.d.ts +32 -0
  22. package/dist/client/link.d.ts +2 -1
  23. package/dist/client/link.js +1884 -1227
  24. package/dist/client/router/boundary-tree.d.ts +1 -1
  25. package/dist/client/router/index.d.ts +2 -2
  26. package/dist/client/router/link-utils.d.ts +14 -1
  27. package/dist/client/router/search/index.d.ts +3 -7
  28. package/dist/client/router/sync-catch-up.d.ts +4 -4
  29. package/dist/client/router/types.d.ts +34 -26
  30. package/dist/client-only.d.ts +1 -0
  31. package/dist/client-only.js +1 -0
  32. package/dist/client.d.ts +11 -169
  33. package/dist/client.js +197 -36
  34. package/dist/config.d.ts +8 -8
  35. package/dist/config.js +10 -10
  36. package/dist/define-route.d.ts +1355 -0
  37. package/dist/devtools/devtools-element.d.ts +1 -0
  38. package/dist/devtools/protocol.d.ts +119 -0
  39. package/dist/furin.d.ts +24 -39
  40. package/dist/furin.js +14432 -7929
  41. package/dist/isomorphic.d.ts +18 -0
  42. package/dist/plugin/binding-scope.d.ts +2 -0
  43. package/dist/plugin/dead-code-elimination.d.ts +3 -0
  44. package/dist/plugin/index.js +1708 -489
  45. package/dist/plugin/route-config-autofix.d.ts +31 -0
  46. package/dist/plugin/routes.d.ts +27 -0
  47. package/dist/plugin/transform-client.d.ts +0 -2
  48. package/dist/plugin/transform-isomorphic.d.ts +9 -0
  49. package/dist/routes.d.ts +6 -0
  50. package/dist/routes.js +1 -0
  51. package/dist/rsc/build/environment.d.ts +2 -0
  52. package/dist/rsc/build/index.d.ts +15 -0
  53. package/dist/rsc/client-codec.d.ts +1 -0
  54. package/dist/rsc/codec.d.ts +4 -0
  55. package/dist/rsc/flight-drain.d.ts +11 -0
  56. package/dist/rsc/render-error.d.ts +17 -0
  57. package/dist/rsc/server-codec.d.ts +2 -0
  58. package/dist/rsc/server-codec.js +24 -0
  59. package/dist/rsc/shared.d.ts +30 -0
  60. package/dist/rsc/symbols.d.ts +2 -0
  61. package/dist/rsc/transport-benchmark.d.ts +13 -0
  62. package/dist/rsc/version.d.ts +7 -0
  63. package/dist/rsc-client.d.ts +4 -0
  64. package/dist/rsc-client.js +166 -0
  65. package/dist/rsc-server.d.ts +11 -0
  66. package/dist/rsc.d.ts +11 -0
  67. package/dist/rsc.js +353 -0
  68. package/dist/server/cache/index.d.ts +2 -2
  69. package/dist/server/cache/invalidation.d.ts +2 -3
  70. package/dist/server/cache/isr-ssg.d.ts +5 -1
  71. package/dist/server/cache/isr.d.ts +9 -0
  72. package/dist/server/cache/route-cache.d.ts +10 -8
  73. package/dist/server/cache/store-view.d.ts +7 -7
  74. package/dist/server/dev-page-plugin.d.ts +11 -5
  75. package/dist/server/devtools/hub.d.ts +11 -0
  76. package/dist/server/devtools/instrumentation.d.ts +22 -0
  77. package/dist/server/devtools/instrumentation.production.d.ts +44 -0
  78. package/dist/server/devtools/plugin.d.ts +3 -0
  79. package/dist/server/devtools/request-context.d.ts +6 -0
  80. package/dist/server/internal.d.ts +5 -0
  81. package/dist/server/internal.js +3 -3
  82. package/dist/server/lang-detect.d.ts +1 -0
  83. package/dist/server/logger.d.ts +4 -0
  84. package/dist/server/render/assemble.d.ts +4 -9
  85. package/dist/server/render/document.d.ts +4 -0
  86. package/dist/server/render/element.d.ts +3 -2
  87. package/dist/server/render/index.d.ts +2 -2
  88. package/dist/server/render/index.ts +6 -3
  89. package/dist/server/render/isr.d.ts +1 -1
  90. package/dist/server/render/loaders.d.ts +9 -1
  91. package/dist/server/render/not-found.d.ts +2 -2
  92. package/dist/server/render/ppr-route.d.ts +8 -0
  93. package/dist/server/render/route-frame-transport.d.ts +2 -0
  94. package/dist/server/render/shell.ts +0 -1
  95. package/dist/server/render/ssg.d.ts +1 -1
  96. package/dist/server/render/ssr.d.ts +9 -9
  97. package/dist/server/render/template.d.ts +4 -0
  98. package/dist/server/router/defined-route.d.ts +24 -0
  99. package/dist/server/router/discovery.d.ts +1 -1
  100. package/dist/server/router/hmr.d.ts +17 -9
  101. package/dist/server/router/patterns.d.ts +7 -1
  102. package/dist/server/router/plugin.d.ts +8 -10
  103. package/dist/server/router/schema-merge.d.ts +3 -0
  104. package/dist/server/router/schemas.d.ts +14 -9
  105. package/dist/server/router/source-version.d.ts +2 -0
  106. package/dist/server/router/types.d.ts +2 -1
  107. package/dist/server/runtime-env.js +2 -2
  108. package/dist/server/sync/adapter.d.ts +45 -26
  109. package/dist/server/sync/config.d.ts +5 -9
  110. package/dist/server/sync/fingerprint.d.ts +2 -1
  111. package/dist/server/sync/index.d.ts +15 -4
  112. package/dist/server/sync/index.js +3023 -0
  113. package/dist/server/sync/notifier.d.ts +18 -0
  114. package/dist/server/sync/plugin.d.ts +53 -54
  115. package/dist/server/sync/postgres/index.d.ts +19 -0
  116. package/dist/server/sync/postgres/index.js +252 -0
  117. package/dist/server/sync/postgres/migrate.d.ts +2 -0
  118. package/dist/server/sync/postgres/migrate.js +17 -0
  119. package/dist/server/sync/postgres/migration.sql +66 -0
  120. package/dist/server/sync/redis/index.d.ts +30 -0
  121. package/dist/server/sync/redis/index.js +336 -0
  122. package/dist/server/sync/redis/scripts.d.ts +4 -0
  123. package/dist/server/sync/response.d.ts +10 -1
  124. package/dist/server/sync/runtime.d.ts +6 -0
  125. package/dist/server/sync/sqlite/index.d.ts +20 -0
  126. package/dist/server/sync/sqlite/index.js +250 -0
  127. package/dist/server/sync/stream.d.ts +12 -11
  128. package/dist/server-only.d.ts +1 -0
  129. package/dist/server-only.js +1 -0
  130. package/dist/shared/await.d.ts +6 -7
  131. package/dist/shared/elysia-contract.d.ts +41 -0
  132. package/dist/shared/parser.d.ts +2 -0
  133. package/dist/shared/route-frame.d.ts +49 -0
  134. package/dist/shared/route-map.d.ts +5 -0
  135. package/dist/shared/utils/index.d.ts +1 -3
  136. package/package.json +86 -41
  137. package/src/adapter/bun.ts +113 -36
  138. package/src/adapter/package.ts +23 -15
  139. package/src/adapter/static.ts +97 -50
  140. package/src/build/bun-build.ts +11 -0
  141. package/src/build/client.ts +41 -26
  142. package/src/build/entry-template.ts +20 -3
  143. package/src/build/hydrate.ts +128 -33
  144. package/src/build/index.ts +14 -2
  145. package/src/build/production-instrumentation.ts +14 -0
  146. package/src/build/route-types.ts +20 -116
  147. package/src/build/scan-server.ts +3 -2
  148. package/src/build/shared.ts +1 -1
  149. package/src/build/ssg-cache.ts +4 -2
  150. package/src/build/types.ts +2 -1
  151. package/src/cli/config.ts +3 -3
  152. package/src/cli/index.ts +58 -27
  153. package/src/client/boundaries.tsx +51 -19
  154. package/src/client/default-screens.tsx +4 -4
  155. package/src/client/define-route.ts +48 -0
  156. package/src/client/document.tsx +165 -0
  157. package/src/client/hmr.ts +40 -0
  158. package/src/client/internal/runtime-types.ts +33 -0
  159. package/src/client/link.tsx +51 -38
  160. package/src/client/router/boundary-tree.tsx +2 -2
  161. package/src/client/router/context.ts +13 -9
  162. package/src/client/router/index.ts +4 -0
  163. package/src/client/router/link-utils.ts +92 -3
  164. package/src/client/router/navigation.ts +9 -15
  165. package/src/client/router/provider.tsx +98 -53
  166. package/src/client/router/search/index.ts +9 -19
  167. package/src/client/router/search-store.ts +5 -1
  168. package/src/client/router/spa-response.ts +3 -4
  169. package/src/client/router/sync-catch-up.ts +9 -8
  170. package/src/client/router/types.ts +52 -26
  171. package/src/client/sync.ts +3 -2
  172. package/src/client-only.ts +1 -0
  173. package/src/client.ts +28 -283
  174. package/src/config.ts +10 -10
  175. package/src/define-route.ts +959 -0
  176. package/src/devtools/devtools-element.js +885 -0
  177. package/src/devtools/protocol.ts +139 -0
  178. package/src/furin.ts +475 -136
  179. package/src/isomorphic.ts +66 -0
  180. package/src/plugin/binding-scope.ts +158 -0
  181. package/src/plugin/dead-code-elimination.ts +202 -0
  182. package/src/plugin/index.ts +14 -18
  183. package/src/plugin/route-config-autofix.ts +1140 -0
  184. package/src/plugin/routes.ts +891 -0
  185. package/src/plugin/transform-client.ts +160 -330
  186. package/src/plugin/transform-isomorphic.ts +464 -0
  187. package/src/routes.ts +6 -0
  188. package/src/rsc/build/environment.ts +30 -0
  189. package/src/rsc/build/index.ts +94 -0
  190. package/src/rsc/client-codec.ts +11 -0
  191. package/src/rsc/codec.ts +85 -0
  192. package/src/rsc/flight-drain.ts +68 -0
  193. package/src/rsc/react-server-dom-webpack.d.ts +23 -0
  194. package/src/rsc/render-error.ts +120 -0
  195. package/src/rsc/server-codec.ts +25 -0
  196. package/src/rsc/shared.tsx +113 -0
  197. package/src/rsc/symbols.ts +2 -0
  198. package/src/rsc/transport-benchmark.ts +73 -0
  199. package/src/rsc/version.ts +57 -0
  200. package/src/rsc-client.ts +12 -0
  201. package/src/rsc-server.tsx +91 -0
  202. package/src/rsc.tsx +75 -0
  203. package/src/server/auto-invalidate/registry.ts +2 -2
  204. package/src/server/auto-invalidate/runtime.ts +32 -6
  205. package/src/server/cache/dev-loader.ts +70 -10
  206. package/src/server/cache/index.ts +7 -3
  207. package/src/server/cache/invalidation.ts +33 -15
  208. package/src/server/cache/isr-ssg.ts +12 -3
  209. package/src/server/cache/isr.ts +84 -9
  210. package/src/server/cache/route-cache.ts +49 -36
  211. package/src/server/cache/store-view.ts +7 -7
  212. package/src/server/context-logger.ts +7 -7
  213. package/src/server/dev-page-plugin.ts +38 -17
  214. package/src/server/devtools/hub.ts +64 -0
  215. package/src/server/devtools/instrumentation.production.ts +80 -0
  216. package/src/server/devtools/instrumentation.ts +72 -0
  217. package/src/server/devtools/plugin.ts +269 -0
  218. package/src/server/devtools/request-context.ts +76 -0
  219. package/src/server/instance.ts +4 -4
  220. package/src/server/internal.ts +5 -0
  221. package/src/server/lang-detect.ts +14 -10
  222. package/src/server/logger.ts +21 -0
  223. package/src/server/render/assemble.ts +58 -36
  224. package/src/server/render/document.tsx +25 -0
  225. package/src/server/render/element.tsx +24 -9
  226. package/src/server/render/index.ts +6 -3
  227. package/src/server/render/isr.ts +182 -117
  228. package/src/server/render/loaders.ts +289 -50
  229. package/src/server/render/not-found.ts +57 -38
  230. package/src/server/render/ppr-route.ts +146 -0
  231. package/src/server/render/route-frame-transport.ts +62 -0
  232. package/src/server/render/shell.ts +0 -1
  233. package/src/server/render/ssg.ts +7 -6
  234. package/src/server/render/ssr.ts +412 -166
  235. package/src/server/render/template.ts +93 -2
  236. package/src/server/router/defined-route.ts +110 -0
  237. package/src/server/router/discovery.ts +165 -48
  238. package/src/server/router/hmr.ts +126 -53
  239. package/src/server/router/patterns.ts +56 -27
  240. package/src/server/router/plugin.ts +210 -200
  241. package/src/server/router/schema-merge.ts +42 -0
  242. package/src/server/router/schemas.ts +61 -76
  243. package/src/server/router/source-version.ts +16 -0
  244. package/src/server/router/types.ts +3 -1
  245. package/src/server/sync/adapter.ts +44 -28
  246. package/src/server/sync/config.ts +9 -27
  247. package/src/server/sync/fingerprint.ts +8 -3
  248. package/src/server/sync/index.ts +37 -13
  249. package/src/server/sync/notifier.ts +109 -0
  250. package/src/server/sync/plugin.ts +184 -89
  251. package/src/server/sync/postgres/index.ts +301 -0
  252. package/src/server/sync/postgres/migrate.ts +16 -0
  253. package/src/server/sync/postgres/migration.sql +66 -0
  254. package/src/server/sync/redis/index.ts +342 -0
  255. package/src/server/sync/redis/scripts.ts +74 -0
  256. package/src/server/sync/response.ts +145 -16
  257. package/src/server/sync/runtime.ts +27 -0
  258. package/src/server/sync/sql.d.ts +4 -0
  259. package/src/server/sync/sqlite/index.ts +337 -0
  260. package/src/server/sync/sqlite/migration.sql +70 -0
  261. package/src/server/sync/stream.ts +137 -81
  262. package/src/server-only.ts +1 -0
  263. package/src/shared/await.tsx +10 -11
  264. package/src/shared/deferred-ndjson.ts +34 -6
  265. package/src/shared/digest.ts +2 -2
  266. package/src/shared/elysia-contract.ts +63 -0
  267. package/src/shared/parser.ts +5 -0
  268. package/src/shared/route-frame.ts +429 -0
  269. package/src/shared/route-map.ts +37 -0
  270. package/src/shared/search-params.ts +7 -7
  271. package/src/shared/utils/index.ts +6 -22
  272. package/dist/build/server-routes-entry.d.ts +0 -13
  273. package/dist/build/server-routes-entry.ts +0 -30
  274. package/dist/server/dev-inspector.d.ts +0 -89
  275. package/dist/server/router/index.d.ts +0 -6
  276. package/dist/server/router/index.js +0 -27
  277. package/dist/server/router/index.ts +0 -28
  278. package/dist/server/sync/memory-adapter.d.ts +0 -17
  279. package/src/build/server-routes-entry.ts +0 -30
  280. package/src/server/dev-inspector.ts +0 -60
  281. package/src/server/router/index.ts +0 -28
  282. package/src/server/sync/memory-adapter.ts +0 -196
@@ -4,16 +4,14 @@ import {
4
4
  findSearchDefaultsForRouteTarget,
5
5
  type SearchParamsInput,
6
6
  } from "../shared/search-params.ts";
7
+ import { CLIENT_FALLBACK_ROUTER, RouterContext, useRouter } from "./router/context.ts";
7
8
  import {
9
+ applyLinkParams,
8
10
  buildHref,
9
- CLIENT_FALLBACK_ROUTER,
10
- type LinkProps,
11
+ navigationHrefPolicy,
11
12
  normalizeHref,
12
- RouterContext,
13
- type RouterContextValue,
14
- type RouteTo,
15
- useRouter,
16
- } from "./router/index.ts";
13
+ } from "./router/link-utils.ts";
14
+ import type { LinkProps, RouterContextValue, RouteTo } from "./router/types.ts";
17
15
 
18
16
  // biome-ignore lint/performance/noBarrelFile: re-exporting router symbols preserves backward compatibility for @teyik0/furin/link consumers
19
17
  export * from "./router/index.ts";
@@ -35,23 +33,31 @@ interface LinkView {
35
33
  function computeLinkView<To extends RouteTo>(
36
34
  {
37
35
  to,
36
+ params,
38
37
  search,
39
38
  hash,
40
39
  children,
41
40
  activeProps,
42
41
  inactiveProps,
43
- }: Pick<LinkProps<To>, "to" | "search" | "hash" | "children" | "activeProps" | "inactiveProps">,
42
+ }: Pick<
43
+ LinkProps<To>,
44
+ "to" | "params" | "search" | "hash" | "children" | "activeProps" | "inactiveProps"
45
+ >,
44
46
  router: RouterContextValue
45
47
  ): LinkView {
46
- const searchDefaults = findSearchDefaultsForRouteTarget(to as string, router.searchRoutes);
47
- const logicalHref = buildHref(
48
+ const resolvedTo = applyLinkParams(
48
49
  to as string,
50
+ params as Record<string, string | number> | null | undefined
51
+ );
52
+ const searchDefaults = findSearchDefaultsForRouteTarget(resolvedTo, router.searchRoutes);
53
+ const logicalHref = buildHref(
54
+ resolvedTo,
49
55
  search as SearchParamsInput | null | undefined,
50
56
  hash,
51
57
  searchDefaults
52
58
  );
53
59
  const logicalHrefWithoutHash = buildHref(
54
- to as string,
60
+ resolvedTo,
55
61
  search as SearchParamsInput | null | undefined,
56
62
  undefined,
57
63
  searchDefaults
@@ -60,14 +66,19 @@ function computeLinkView<To extends RouteTo>(
60
66
  logicalHref.startsWith("http://") ||
61
67
  logicalHref.startsWith("https://") ||
62
68
  logicalHref.startsWith("//");
63
- const href = isAbsolute ? logicalHref : router.basePath + logicalHref;
69
+ const candidateHref = isAbsolute ? logicalHref : router.basePath + logicalHref;
70
+ const href = navigationHrefPolicy(candidateHref, undefined) === "blocked" ? "#" : candidateHref;
64
71
  const isActive = !isAbsolute && router.currentHref === normalizeHref(logicalHrefWithoutHash);
65
72
  const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
66
73
  const extraProps: React.AnchorHTMLAttributes<HTMLAnchorElement> = {
67
74
  ...(inactiveProps && !isActive ? inactiveProps() : {}),
68
75
  ...(activeProps ? activeProps({ isActive }) : {}),
69
76
  };
70
- return { logicalHref, href, isActive, resolvedChildren, extraProps };
77
+ return { extraProps, href, isActive, logicalHref, resolvedChildren };
78
+ }
79
+
80
+ function isSameOriginUrl(url: string): boolean {
81
+ return navigationHrefPolicy(url, window.location.origin) === "internal";
71
82
  }
72
83
 
73
84
  /**
@@ -78,6 +89,7 @@ function computeLinkView<To extends RouteTo>(
78
89
  */
79
90
  function LinkInteractive<To extends RouteTo>({
80
91
  to,
92
+ params,
81
93
  search,
82
94
  hash,
83
95
  preload,
@@ -104,7 +116,7 @@ function LinkInteractive<To extends RouteTo>({
104
116
  // logicalHref: route-relative path (no basePath), used for navigation + active state.
105
117
  // physicalHref (href): what the browser sees — basePath + logicalHref.
106
118
  const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView(
107
- { to, search, hash, children, activeProps, inactiveProps },
119
+ { activeProps, children, hash, inactiveProps, params, search, to },
108
120
  router
109
121
  );
110
122
  const effectivePreload = preload ?? router.defaultPreload;
@@ -115,6 +127,7 @@ function LinkInteractive<To extends RouteTo>({
115
127
  const triggerPrefetch = useCallback(() => {
116
128
  // prefetch() expects the logical href (no basePath prefix).
117
129
  prefetch(logicalHref, { staleTime: effectiveStaleTime });
130
+ // react-doctor-disable-next-line react-doctor/exhaustive-deps
118
131
  }, [prefetch, logicalHref, effectiveStaleTime]);
119
132
 
120
133
  // "render": preload immediately on mount
@@ -122,6 +135,7 @@ function LinkInteractive<To extends RouteTo>({
122
135
  if (effectivePreload === "render") {
123
136
  triggerPrefetch();
124
137
  }
138
+ // react-doctor-disable-next-line react-doctor/exhaustive-deps
125
139
  }, [effectivePreload, triggerPrefetch]);
126
140
 
127
141
  // "viewport": preload when link enters viewport
@@ -140,6 +154,7 @@ function LinkInteractive<To extends RouteTo>({
140
154
  );
141
155
  observer.observe(anchorRef.current);
142
156
  return () => observer.disconnect();
157
+ // react-doctor-disable-next-line react-doctor/exhaustive-deps
143
158
  }, [effectivePreload, triggerPrefetch]);
144
159
 
145
160
  // Clear any pending intent prefetch timer on unmount to avoid leaking
@@ -154,14 +169,6 @@ function LinkInteractive<To extends RouteTo>({
154
169
  []
155
170
  );
156
171
 
157
- const isInternal = (url: string): boolean => {
158
- try {
159
- return new URL(url, window.location.origin).origin === window.location.origin;
160
- } catch {
161
- return false;
162
- }
163
- };
164
-
165
172
  const handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
166
173
  onClick?.(e);
167
174
  if (e.defaultPrevented) {
@@ -179,8 +186,12 @@ function LinkInteractive<To extends RouteTo>({
179
186
  if (anchorProps.target && anchorProps.target !== "_self") {
180
187
  return;
181
188
  }
189
+ if (navigationHrefPolicy(logicalHref, window.location.origin) === "blocked") {
190
+ e.preventDefault();
191
+ return;
192
+ }
182
193
  // Let browser handle external links
183
- if (!isInternal(href)) {
194
+ if (!isSameOriginUrl(href)) {
184
195
  return;
185
196
  }
186
197
  e.preventDefault();
@@ -196,7 +207,7 @@ function LinkInteractive<To extends RouteTo>({
196
207
 
197
208
  const handleMouseEnter = (e: React.MouseEvent<HTMLAnchorElement>) => {
198
209
  onMouseEnter?.(e);
199
- if (!disabled && effectivePreload === "intent" && isInternal(href)) {
210
+ if (!disabled && effectivePreload === "intent" && isSameOriginUrl(href)) {
200
211
  intentTimerRef.current = setTimeout(triggerPrefetch, effectiveDelay);
201
212
  }
202
213
  };
@@ -211,7 +222,7 @@ function LinkInteractive<To extends RouteTo>({
211
222
 
212
223
  const handleFocus = (e: React.FocusEvent<HTMLAnchorElement>) => {
213
224
  onFocus?.(e);
214
- if (!disabled && effectivePreload === "intent" && isInternal(href)) {
225
+ if (!disabled && effectivePreload === "intent" && isSameOriginUrl(href)) {
215
226
  triggerPrefetch();
216
227
  }
217
228
  };
@@ -219,13 +230,13 @@ function LinkInteractive<To extends RouteTo>({
219
230
  return createElement(
220
231
  "a",
221
232
  {
222
- ref: anchorRef,
223
- href,
224
233
  "data-furin-link": true,
234
+ href,
225
235
  onClick: handleClick,
236
+ onFocus: handleFocus,
226
237
  onMouseEnter: handleMouseEnter,
227
238
  onMouseLeave: handleMouseLeave,
228
- onFocus: handleFocus,
239
+ ref: anchorRef,
229
240
  ...(isActive ? { "data-status": "active" } : {}),
230
241
  ...anchorProps,
231
242
  ...extraProps,
@@ -245,20 +256,20 @@ function LinkInteractive<To extends RouteTo>({
245
256
  export const SSR_FALLBACK_ROUTER: RouterContextValue = {
246
257
  basePath: "",
247
258
  currentHref: "/",
248
- search: {},
249
- searchRoutes: [],
250
- navigate: (_href, _opts) => Promise.resolve(),
251
- prefetch: (_href, _opts) => {
259
+ defaultPreload: "intent",
260
+ defaultPreloadDelay: 50,
261
+ defaultPreloadStaleTime: 30_000,
262
+ invalidatePrefetch: (_path, _type) => {
252
263
  /* noop */
253
264
  },
254
- invalidatePrefetch: (_path, _type) => {
265
+ isNavigating: false,
266
+ navigate: (_href, _opts) => Promise.resolve(),
267
+ prefetch: (_href, _opts) => {
255
268
  /* noop */
256
269
  },
257
270
  refresh: (_opts) => Promise.resolve(),
258
- isNavigating: false,
259
- defaultPreload: "intent",
260
- defaultPreloadDelay: 50,
261
- defaultPreloadStaleTime: 30_000,
271
+ search: {},
272
+ searchRoutes: [],
262
273
  };
263
274
 
264
275
  /**
@@ -275,6 +286,7 @@ function renderLinkElement<To extends RouteTo>(
275
286
  // Destructure to strip Link-specific and client-only props before spreading onto <a>.
276
287
  const {
277
288
  to: _to,
289
+ params: _params,
278
290
  search: _search,
279
291
  hash: _hash,
280
292
  children: _children,
@@ -298,8 +310,8 @@ function renderLinkElement<To extends RouteTo>(
298
310
  return createElement(
299
311
  "a",
300
312
  {
301
- href,
302
313
  "data-furin-link": true,
314
+ href,
303
315
  ...(isActive ? { "data-status": "active" } : {}),
304
316
  ...anchorProps,
305
317
  ...extraProps,
@@ -345,3 +357,4 @@ export function Link<To extends RouteTo>(props: LinkProps<To>): React.ReactEleme
345
357
  // `@teyik0/furin/link` (already a client-only bundle entry) without requiring
346
358
  // apps to add "seroval" as a direct dependency.
347
359
  export { fromCrossJSON } from "seroval";
360
+ export { parseDeferredNdjson } from "../shared/deferred-ndjson.ts";
@@ -1,7 +1,7 @@
1
1
  import type React from "react";
2
2
  import { createElement } from "react";
3
- import type { RuntimeRoute } from "../../client.ts";
4
3
  import { type BoundaryOptions, FurinErrorBoundary, wrapSegmentBoundaries } from "../boundaries.tsx";
4
+ import type { RuntimeRoute } from "../internal/runtime-types.ts";
5
5
  import { FurinServerError } from "../server-error.ts";
6
6
  import { RouterContext } from "./context.ts";
7
7
  import type {
@@ -94,7 +94,7 @@ export function buildPageElement(
94
94
  // Inside-out: at each non-root depth wrap the subtree with its same-depth
95
95
  // boundary (so the boundary sits INSIDE the layout), then wrap with the
96
96
  // layout itself when this route declares one.
97
- for (let i = chain.length - 1; i >= rootOffset; i--) {
97
+ for (let i = chain.length - 1; i >= rootOffset; i -= 1) {
98
98
  element = wrapSegmentBoundaries(element, byDepth.get(i), options);
99
99
  const Layout = chain[i]?.layout;
100
100
  if (Layout) {
@@ -1,4 +1,5 @@
1
1
  import { createContext, useContext } from "react";
2
+ import { navigationHrefPolicy } from "./link-utils.ts";
2
3
  import type { RouterContextValue } from "./types.ts";
3
4
 
4
5
  export const RouterContext = createContext<RouterContextValue | null>(null);
@@ -8,26 +9,29 @@ export const CLIENT_FALLBACK_ROUTER: RouterContextValue = {
8
9
  // Use the same "/" as SSR_FALLBACK_ROUTER so SSR and client render the
9
10
  // same active-state when no RouterProvider is present, avoiding hydration mismatches.
10
11
  currentHref: "/",
11
- search: {},
12
- searchRoutes: [],
12
+ defaultPreload: "intent",
13
+ defaultPreloadDelay: 50,
14
+ defaultPreloadStaleTime: 30_000,
15
+ invalidatePrefetch: (_path, _type) => {
16
+ /* noop fallback */
17
+ },
18
+ isNavigating: false,
13
19
  navigate: (href, _opts) => {
20
+ if (navigationHrefPolicy(href, window.location.origin) === "blocked") {
21
+ return Promise.reject(new Error("[furin] Unsafe navigation URL."));
22
+ }
14
23
  window.location.href = href;
15
24
  return Promise.resolve();
16
25
  },
17
26
  prefetch: (_href, _opts) => {
18
27
  /* noop fallback */
19
28
  },
20
- invalidatePrefetch: (_path, _type) => {
21
- /* noop fallback */
22
- },
23
29
  refresh: (_opts) => {
24
30
  window.location.reload();
25
31
  return Promise.resolve();
26
32
  },
27
- isNavigating: false,
28
- defaultPreload: "intent",
29
- defaultPreloadDelay: 50,
30
- defaultPreloadStaleTime: 30_000,
33
+ search: {},
34
+ searchRoutes: [],
31
35
  };
32
36
 
33
37
  /**
@@ -11,6 +11,9 @@ export {
11
11
  export {
12
12
  applyRevalidateHeader,
13
13
  buildHref,
14
+ decodeHashFragment,
15
+ isSameOriginFetchResult,
16
+ navigationHrefPolicy,
14
17
  normalizeHref,
15
18
  normalizePath,
16
19
  shouldAutoRefreshPath,
@@ -47,6 +50,7 @@ export type {
47
50
  PreloadStrategy,
48
51
  RootBoundaryOptions,
49
52
  RouteManifest,
53
+ RouteParamsOf,
50
54
  RouterContextValue,
51
55
  RouterProviderProps,
52
56
  RouterState,
@@ -5,6 +5,95 @@ const HASH_FRAGMENT_RE = /#.*$/;
5
5
  /** Strips one or more trailing slashes — used by `buildDataEndpoint` in static mode. */
6
6
  export const TRAILING_SLASHES_RE = /\/+$/;
7
7
 
8
+ export type NavigationHrefPolicy = "blocked" | "external" | "internal";
9
+
10
+ export function navigationHrefPolicy(
11
+ href: string,
12
+ currentOrigin: string | undefined
13
+ ): NavigationHrefPolicy {
14
+ for (let index = 0; index < href.length; index += 1) {
15
+ const code = href.charCodeAt(index);
16
+ if (code <= 31 || code === 127) {
17
+ return "blocked";
18
+ }
19
+ }
20
+ let url: URL;
21
+ try {
22
+ url = new URL(href, currentOrigin ?? "http://localhost");
23
+ } catch {
24
+ return "blocked";
25
+ }
26
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
27
+ return "blocked";
28
+ }
29
+ if (currentOrigin === undefined) {
30
+ return href.startsWith("http://") || href.startsWith("https://") || href.startsWith("//")
31
+ ? "external"
32
+ : "internal";
33
+ }
34
+ return url.origin === currentOrigin ? "internal" : "external";
35
+ }
36
+
37
+ export function decodeHashFragment(fragment: string): string {
38
+ try {
39
+ return decodeURIComponent(fragment);
40
+ } catch {
41
+ return fragment;
42
+ }
43
+ }
44
+
45
+ export function isSameOriginFetchResult(
46
+ input: RequestInfo | URL,
47
+ responseUrl: string,
48
+ currentOrigin: string
49
+ ): boolean {
50
+ if (responseUrl.length === 0) {
51
+ return false;
52
+ }
53
+ try {
54
+ let inputUrl: string;
55
+ if (typeof input === "string") {
56
+ inputUrl = input;
57
+ } else if (input instanceof URL) {
58
+ inputUrl = input.href;
59
+ } else {
60
+ inputUrl = input.url;
61
+ }
62
+ return (
63
+ new URL(inputUrl, currentOrigin).origin === currentOrigin &&
64
+ new URL(responseUrl, currentOrigin).origin === currentOrigin
65
+ );
66
+ } catch {
67
+ return false;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Substitutes typed path params into a route pattern: `/board/:boardId` with
73
+ * `{ boardId: 42 }` → `/board/42`. The `*` wildcard segment (catch-all) is
74
+ * replaced from `params["*"]`. Unknown segments are left untouched so
75
+ * partially-applied patterns stay visible.
76
+ *
77
+ * @internal Exported for unit testing only.
78
+ */
79
+ export function applyLinkParams(
80
+ to: string,
81
+ params: Record<string, string | number> | null | undefined
82
+ ): string {
83
+ if (!params) {
84
+ return to;
85
+ }
86
+ let url = to.replaceAll(/:([a-zA-Z0-9_]+)/g, (match: string, name: string) =>
87
+ name in params ? encodeURIComponent(String(params[name])) : match
88
+ );
89
+ const wildcard: string | number | undefined = params["*"];
90
+ if (wildcard !== undefined && url.includes("/*")) {
91
+ const encodedWildcard = String(wildcard).split("/").map(encodeURIComponent).join("/");
92
+ url = url.replace("/*", () => `/${encodedWildcard}`);
93
+ }
94
+ return url;
95
+ }
96
+
8
97
  /**
9
98
  * Builds a full href string from a pathname, optional search params, and optional hash.
10
99
  * Null/undefined search values are omitted.
@@ -90,7 +179,7 @@ export function stripHashFromHref(href: string): string {
90
179
  * Query strings and hashes are preserved and re-attached after normalization. */
91
180
  export function normalizeHref(href: string): string {
92
181
  const url = new URL(href, "http://localhost");
93
- let pathname = url.pathname;
182
+ let { pathname } = url;
94
183
  if (pathname !== "/") {
95
184
  pathname = pathname.replace(/\/+$/g, "");
96
185
  }
@@ -118,7 +207,7 @@ export function shouldRefetch(entry: CacheEntry): boolean {
118
207
  * @internal Exported for unit testing only.
119
208
  */
120
209
  export function shouldInterceptClick(
121
- anchor: { href: string; target: string; hasAttribute(name: string): boolean },
210
+ anchor: { href: string; target: string; hasAttribute: (name: string) => boolean },
122
211
  event: { metaKey: boolean; ctrlKey: boolean; shiftKey: boolean; altKey: boolean },
123
212
  basePath: string,
124
213
  currentOrigin: string,
@@ -136,7 +225,7 @@ export function shouldInterceptClick(
136
225
  return null;
137
226
  }
138
227
 
139
- const href = anchor.href;
228
+ const { href } = anchor;
140
229
  if (!href) {
141
230
  return null;
142
231
  }
@@ -4,7 +4,7 @@ import {
4
4
  type SearchParamsInput,
5
5
  } from "../../shared/search-params.ts";
6
6
  import { useRouter } from "./context.ts";
7
- import { buildHref } from "./link-utils.ts";
7
+ import { buildHref, navigationHrefPolicy } from "./link-utils.ts";
8
8
  import type { RouteSearch, RouteTo } from "./types.ts";
9
9
 
10
10
  export interface NavigateInput<To extends RouteTo> {
@@ -18,19 +18,6 @@ export interface NavigateInput<To extends RouteTo> {
18
18
  export type Navigate = <To extends RouteTo>(next: NavigateInput<To>) => Promise<void>;
19
19
  type NavigateOptions = Parameters<ReturnType<typeof useRouter>["navigate"]>[1];
20
20
 
21
- function isExternalAbsoluteHref(href: string): boolean {
22
- if (href.startsWith("//")) {
23
- return true;
24
- }
25
- if (!(href.startsWith("http://") || href.startsWith("https://"))) {
26
- return false;
27
- }
28
- if (typeof window === "undefined") {
29
- return true;
30
- }
31
- return new URL(href).origin !== window.location.origin;
32
- }
33
-
34
21
  export function useNavigate(): Navigate {
35
22
  const router = useRouter();
36
23
 
@@ -46,7 +33,14 @@ export function useNavigate(): Navigate {
46
33
  next.hash,
47
34
  searchDefaults
48
35
  );
49
- if (isExternalAbsoluteHref(href) && typeof window !== "undefined") {
36
+ const policy = navigationHrefPolicy(
37
+ href,
38
+ typeof window === "undefined" ? undefined : window.location.origin
39
+ );
40
+ if (policy === "blocked") {
41
+ return Promise.reject(new Error("[furin] Unsafe navigation URL."));
42
+ }
43
+ if (policy === "external" && typeof window !== "undefined") {
50
44
  window.location.assign(href);
51
45
  return Promise.resolve();
52
46
  }