@teyik0/furin 0.1.0-alpha.11 → 0.1.0-alpha.13

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/dist/link.js CHANGED
@@ -1,4 +1,7 @@
1
1
  // @bun
2
+ // src/link.tsx
3
+ import { createElement as createElement2, useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2 } from "react";
4
+
2
5
  // ../../node_modules/.bun/evlog@2.14.1+6b630eaba8c4f70c/node_modules/evlog/dist/utils.mjs
3
6
  function formatDuration(ms) {
4
7
  if (ms < 1000)
@@ -691,13 +694,14 @@ function finalizeAudit(event) {
691
694
  return;
692
695
  event.audit = decorateAudit(a, String(event.timestamp));
693
696
  }
694
- // src/link.tsx
697
+ // src/router-provider.tsx
695
698
  import {
696
699
  createContext,
697
700
  createElement,
698
701
  useCallback,
699
702
  useContext,
700
703
  useEffect,
704
+ useLayoutEffect,
701
705
  useMemo,
702
706
  useRef,
703
707
  useState
@@ -1115,7 +1119,7 @@ class FurinNotFoundBoundary extends Component {
1115
1119
  }
1116
1120
  }
1117
1121
 
1118
- // src/link.tsx
1122
+ // src/router-provider.tsx
1119
1123
  import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
1120
1124
  function buildHref(to, search, hash) {
1121
1125
  let url = to;
@@ -1165,7 +1169,8 @@ function shouldAutoRefreshPath(currentPath, invalidations) {
1165
1169
  }
1166
1170
  var RouterContext = createContext(null);
1167
1171
  function useRouter() {
1168
- return useContext(RouterContext) ?? {
1172
+ const ctx = useContext(RouterContext);
1173
+ return ctx ?? {
1169
1174
  basePath: "",
1170
1175
  currentHref: "/",
1171
1176
  navigate: (href) => {
@@ -1191,6 +1196,20 @@ var HASH_FRAGMENT_RE = /#.*$/;
1191
1196
  function stripHashFromHref(href) {
1192
1197
  return href.replace(HASH_FRAGMENT_RE, "");
1193
1198
  }
1199
+ function normalizeHref(href) {
1200
+ const url = new URL(href, "http://localhost");
1201
+ let pathname = url.pathname;
1202
+ if (pathname !== "/") {
1203
+ pathname = pathname.replace(/\/+$/g, "");
1204
+ }
1205
+ return pathname + url.search + url.hash;
1206
+ }
1207
+ function normalizePath(path) {
1208
+ if (path === "/" || path === "") {
1209
+ return path;
1210
+ }
1211
+ return path.endsWith("/") ? path.slice(0, -1) : path;
1212
+ }
1194
1213
  function classifySpaResponse(status, data) {
1195
1214
  if (!data) {
1196
1215
  return { kind: "bail" };
@@ -1204,6 +1223,40 @@ function classifySpaResponse(status, data) {
1204
1223
  }
1205
1224
  return { kind: "bail" };
1206
1225
  }
1226
+ function shouldInterceptClick(anchor, event, basePath, currentOrigin, currentPathname) {
1227
+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
1228
+ return null;
1229
+ }
1230
+ if (anchor.target && anchor.target !== "_self") {
1231
+ return null;
1232
+ }
1233
+ if (anchor.hasAttribute("download")) {
1234
+ return null;
1235
+ }
1236
+ const href = anchor.href;
1237
+ if (!href) {
1238
+ return null;
1239
+ }
1240
+ let url;
1241
+ try {
1242
+ url = new URL(href, currentOrigin);
1243
+ } catch {
1244
+ return null;
1245
+ }
1246
+ if (url.origin !== currentOrigin) {
1247
+ return null;
1248
+ }
1249
+ if (normalizePath(url.pathname) === normalizePath(currentPathname) && url.hash) {
1250
+ return null;
1251
+ }
1252
+ const logicalPath = normalizeHref(toLogical(url.pathname, basePath));
1253
+ const normalizedBase = normalizePath(basePath);
1254
+ const normalizedPathname = normalizePath(url.pathname);
1255
+ if (normalizedBase && normalizedPathname !== normalizedBase && !normalizedPathname.startsWith(`${normalizedBase}/`)) {
1256
+ return null;
1257
+ }
1258
+ return logicalPath + url.search + url.hash;
1259
+ }
1207
1260
  function pickDeepestNotFound(boundaries) {
1208
1261
  if (!boundaries) {
1209
1262
  return;
@@ -1280,32 +1333,6 @@ function buildPageElement(match, root, data, options) {
1280
1333
  }
1281
1334
  return element;
1282
1335
  }
1283
- function handleScrollRestoration(href, navigationToken, navVersion) {
1284
- const destUrl = new URL(href, window.location.origin);
1285
- if (destUrl.hash) {
1286
- const id = decodeURIComponent(destUrl.hash.slice(1));
1287
- const scrollToHashTarget = () => {
1288
- if (navVersion.current !== navigationToken) {
1289
- return;
1290
- }
1291
- const element = document.getElementById(id);
1292
- if (element) {
1293
- element.scrollIntoView({ behavior: "instant", block: "start" });
1294
- }
1295
- };
1296
- window.requestAnimationFrame(() => {
1297
- scrollToHashTarget();
1298
- if (document.getElementById(id)) {
1299
- return;
1300
- }
1301
- window.requestAnimationFrame(() => {
1302
- scrollToHashTarget();
1303
- });
1304
- });
1305
- } else {
1306
- window.scrollTo({ top: 0, behavior: "instant" });
1307
- }
1308
- }
1309
1336
  var SCROLL_STORAGE_KEY = "__furin_scroll__";
1310
1337
  function getHistoryKey(state) {
1311
1338
  return state?._furinKey;
@@ -1325,23 +1352,6 @@ function saveScrollPosition(key) {
1325
1352
  sessionStorage.setItem(SCROLL_STORAGE_KEY, JSON.stringify(positions));
1326
1353
  } catch {}
1327
1354
  }
1328
- function restoreScrollPosition(key, token, version) {
1329
- try {
1330
- const raw = sessionStorage.getItem(SCROLL_STORAGE_KEY);
1331
- const positions = raw ? JSON.parse(raw) : {};
1332
- const y = positions[key] ?? 0;
1333
- window.requestAnimationFrame(() => {
1334
- window.requestAnimationFrame(() => {
1335
- if (version.current !== token) {
1336
- return;
1337
- }
1338
- window.scrollTo({ top: y, behavior: "instant" });
1339
- });
1340
- });
1341
- } catch {
1342
- window.scrollTo({ top: 0, behavior: "instant" });
1343
- }
1344
- }
1345
1355
  function isStaleDeployResponse(res) {
1346
1356
  const serverBuildId = res.headers.get("x-furin-build-id");
1347
1357
  if (!serverBuildId) {
@@ -1376,13 +1386,19 @@ function RouterProvider({
1376
1386
  initialData,
1377
1387
  initialDigest,
1378
1388
  initialNotFound,
1379
- autoRefresh = true,
1380
- basePath = "",
1381
- defaultPreload = "intent",
1382
- defaultPreloadDelay = 50,
1383
- defaultPreloadStaleTime = 30000,
1384
- prefetchCacheSize = 50
1389
+ autoRefresh,
1390
+ basePath,
1391
+ defaultPreload,
1392
+ defaultPreloadDelay,
1393
+ defaultPreloadStaleTime,
1394
+ prefetchCacheSize
1385
1395
  }) {
1396
+ const _autoRefresh = autoRefresh ?? true;
1397
+ const _basePath = basePath ?? "";
1398
+ const _defaultPreload = defaultPreload ?? "intent";
1399
+ const _defaultPreloadDelay = defaultPreloadDelay ?? 50;
1400
+ const _defaultPreloadStaleTime = defaultPreloadStaleTime ?? 30000;
1401
+ const _prefetchCacheSize = prefetchCacheSize ?? 50;
1386
1402
  const [state, setState] = useState(() => ({
1387
1403
  match: initialMatch,
1388
1404
  data: initialData,
@@ -1393,10 +1409,11 @@ function RouterProvider({
1393
1409
  if (typeof window === "undefined") {
1394
1410
  return "/";
1395
1411
  }
1396
- return toLogical(window.location.pathname, basePath) + window.location.search;
1412
+ return normalizeHref(toLogical(window.location.pathname, _basePath)) + window.location.search;
1397
1413
  });
1398
1414
  const prefetchCache = useRef(new Map);
1399
1415
  const navVersion = useRef(0);
1416
+ const pendingScrollRef = useRef(null);
1400
1417
  const currentMatchRef = useRef(initialMatch);
1401
1418
  const rootBoundaries = useMemo(() => {
1402
1419
  for (const route of routes) {
@@ -1407,11 +1424,12 @@ function RouterProvider({
1407
1424
  }
1408
1425
  return;
1409
1426
  }, [routes]);
1410
- const fetchPageState = useCallback(async (logicalHref) => {
1427
+ const fetchPageState = useCallback(async (rawLogicalHref) => {
1428
+ const logicalHref = normalizeHref(rawLogicalHref);
1411
1429
  try {
1412
- const physicalHref = basePath + logicalHref;
1430
+ const physicalHref = _basePath + logicalHref;
1413
1431
  const url = new URL(physicalHref, window.location.origin);
1414
- const logicalPathname = toLogical(url.pathname, basePath);
1432
+ const logicalPathname = toLogical(url.pathname, _basePath);
1415
1433
  const match = routes.find((r) => r.regex.test(logicalPathname));
1416
1434
  if (!match) {
1417
1435
  const res2 = await fetch(physicalHref);
@@ -1419,7 +1437,7 @@ function RouterProvider({
1419
1437
  window.location.href = physicalHref;
1420
1438
  return null;
1421
1439
  }
1422
- const { data: data2, finalHref: finalHref2, title: title2 } = await parsePageResponse(res2, basePath);
1440
+ const { data: data2, finalHref: finalHref2, title: title2 } = await parsePageResponse(res2, _basePath);
1423
1441
  const kind2 = classifySpaResponse(res2.status, data2);
1424
1442
  if (kind2.kind !== "not-found") {
1425
1443
  return null;
@@ -1439,7 +1457,7 @@ function RouterProvider({
1439
1457
  window.location.href = physicalHref;
1440
1458
  return null;
1441
1459
  }
1442
- const { data, finalHref, title } = await parsePageResponse(res, basePath);
1460
+ const { data, finalHref, title } = await parsePageResponse(res, _basePath);
1443
1461
  const kind = classifySpaResponse(res.status, data);
1444
1462
  if (kind.kind === "bail") {
1445
1463
  _log.warn({ action: "navigate_server_error", href: physicalHref, status: res.status });
@@ -1462,10 +1480,10 @@ function RouterProvider({
1462
1480
  }
1463
1481
  return { match: loadedMatch, data: data ?? {}, title, finalHref };
1464
1482
  } catch (err) {
1465
- _log.error({ action: "navigate_failed", href: basePath + logicalHref, error: String(err) });
1483
+ _log.error({ action: "navigate_failed", href: _basePath + logicalHref, error: String(err) });
1466
1484
  return null;
1467
1485
  }
1468
- }, [routes, basePath, rootBoundaries]);
1486
+ }, [routes, _basePath, rootBoundaries]);
1469
1487
  const invalidatePrefetch = useCallback((path, type = "page") => {
1470
1488
  const normalizedPath = stripHashFromHref(path);
1471
1489
  if (type === "page") {
@@ -1485,7 +1503,7 @@ function RouterProvider({
1485
1503
  }
1486
1504
  }, []);
1487
1505
  const prefetch = useCallback((href, opts) => {
1488
- const staleTime = opts?.staleTime ?? defaultPreloadStaleTime;
1506
+ const staleTime = opts?.staleTime ?? _defaultPreloadStaleTime;
1489
1507
  const existing = prefetchCache.current.get(href);
1490
1508
  if (existing && !shouldRefetch(existing)) {
1491
1509
  return;
@@ -1495,12 +1513,13 @@ function RouterProvider({
1495
1513
  createdAt: Date.now(),
1496
1514
  staleTime
1497
1515
  });
1498
- if (prefetchCache.current.size > prefetchCacheSize) {
1516
+ if (prefetchCache.current.size > _prefetchCacheSize) {
1499
1517
  const oldest = prefetchCache.current.keys().next().value;
1500
1518
  prefetchCache.current.delete(oldest);
1501
1519
  }
1502
- }, [fetchPageState, defaultPreloadStaleTime, prefetchCacheSize]);
1503
- const navigate = useCallback(async (logicalHref, opts) => {
1520
+ }, [fetchPageState, _defaultPreloadStaleTime, _prefetchCacheSize]);
1521
+ const navigate = useCallback(async (rawLogicalHref, opts) => {
1522
+ const logicalHref = normalizeHref(rawLogicalHref);
1504
1523
  prefetch(logicalHref);
1505
1524
  const myVersion = ++navVersion.current;
1506
1525
  setIsNavigating(true);
@@ -1515,7 +1534,7 @@ function RouterProvider({
1515
1534
  href: logicalHref,
1516
1535
  reason: "prefetch_returned_null"
1517
1536
  });
1518
- window.location.href = basePath + logicalHref;
1537
+ window.location.href = _basePath + logicalHref;
1519
1538
  return;
1520
1539
  }
1521
1540
  currentMatchRef.current = newState.match;
@@ -1524,7 +1543,7 @@ function RouterProvider({
1524
1543
  document.title = newState.title;
1525
1544
  }
1526
1545
  const effectiveLogical = newState.finalHref ?? logicalHref;
1527
- const physicalEffective = basePath + effectiveLogical;
1546
+ const physicalEffective = _basePath + effectiveLogical;
1528
1547
  if (opts?.replace) {
1529
1548
  window.history.replaceState({
1530
1549
  ...history.state ?? {},
@@ -1538,23 +1557,23 @@ function RouterProvider({
1538
1557
  window.history.pushState({ _furinKey: generateHistoryKey() }, "", physicalEffective);
1539
1558
  }
1540
1559
  const effectiveUrl = new URL(physicalEffective, window.location.origin);
1541
- const logicalPath = toLogical(effectiveUrl.pathname, basePath);
1560
+ const logicalPath = normalizeHref(toLogical(effectiveUrl.pathname, _basePath));
1542
1561
  setCurrentHref(logicalPath + effectiveUrl.search);
1543
1562
  if (opts?.resetScroll ?? true) {
1544
- handleScrollRestoration(physicalEffective, myVersion, navVersion);
1563
+ pendingScrollRef.current = { type: "reset", href: physicalEffective };
1545
1564
  }
1546
1565
  } finally {
1547
1566
  if (navVersion.current === myVersion) {
1548
1567
  setIsNavigating(false);
1549
1568
  }
1550
1569
  }
1551
- }, [prefetch, basePath]);
1570
+ }, [prefetch, _basePath]);
1552
1571
  const refresh = useCallback(async (opts) => {
1553
- const logicalPath = toLogical(window.location.pathname, basePath);
1572
+ const logicalPath = toLogical(window.location.pathname, _basePath);
1554
1573
  const logicalHref = logicalPath + window.location.search;
1555
1574
  invalidatePrefetch(logicalHref, "page");
1556
1575
  await navigate(logicalHref, { replace: true, resetScroll: opts?.resetScroll ?? false });
1557
- }, [navigate, invalidatePrefetch, basePath]);
1576
+ }, [navigate, invalidatePrefetch, _basePath]);
1558
1577
  useEffect(() => {
1559
1578
  if (typeof window !== "undefined") {
1560
1579
  window.__FURIN_HMR_REFRESH__ = refresh;
@@ -1563,67 +1582,118 @@ function RouterProvider({
1563
1582
  };
1564
1583
  }
1565
1584
  }, [refresh]);
1566
- const handlePopState = useCallback(async () => {
1585
+ const handlePopState = useCallback(() => {
1567
1586
  const destKey = getHistoryKey(history.state);
1568
- const logicalPath = toLogical(window.location.pathname, basePath);
1587
+ const logicalPath = normalizeHref(toLogical(window.location.pathname, _basePath));
1569
1588
  const logicalHref = logicalPath + window.location.search;
1570
1589
  const myVersion = ++navVersion.current;
1571
1590
  setIsNavigating(true);
1572
- try {
1573
- const cached = prefetchCache.current.get(logicalHref);
1574
- let newState;
1575
- if (cached && !shouldRefetch(cached)) {
1576
- newState = await cached.promise;
1577
- } else {
1578
- newState = await fetchPageState(logicalHref);
1579
- }
1580
- if (navVersion.current !== myVersion) {
1581
- return;
1582
- }
1583
- if (!newState) {
1584
- _log.warn({
1585
- action: "popstate_fallback",
1586
- href: logicalHref,
1587
- reason: "fetchPageState_returned_null"
1588
- });
1589
- window.location.reload();
1590
- return;
1591
- }
1592
- currentMatchRef.current = newState.match;
1593
- setState(newState);
1594
- if (newState.title) {
1595
- document.title = newState.title;
1596
- }
1597
- const effectiveLogical = newState.finalHref ?? logicalHref;
1598
- if (newState.finalHref) {
1599
- window.history.replaceState(history.state, "", basePath + effectiveLogical);
1600
- }
1601
- setCurrentHref(effectiveLogical);
1602
- if (destKey) {
1603
- restoreScrollPosition(destKey, myVersion, navVersion);
1604
- } else {
1605
- window.scrollTo({ top: 0, behavior: "instant" });
1606
- }
1607
- } finally {
1608
- if (navVersion.current === myVersion) {
1609
- setIsNavigating(false);
1591
+ (async () => {
1592
+ try {
1593
+ const cached = prefetchCache.current.get(logicalHref);
1594
+ let newState;
1595
+ if (cached && !shouldRefetch(cached)) {
1596
+ newState = await cached.promise;
1597
+ } else {
1598
+ newState = await fetchPageState(logicalHref);
1599
+ }
1600
+ if (navVersion.current !== myVersion) {
1601
+ return;
1602
+ }
1603
+ if (!newState) {
1604
+ _log.warn({
1605
+ action: "popstate_fallback",
1606
+ href: logicalHref,
1607
+ reason: "fetchPageState_returned_null"
1608
+ });
1609
+ window.location.reload();
1610
+ return;
1611
+ }
1612
+ currentMatchRef.current = newState.match;
1613
+ setState(newState);
1614
+ if (newState.title) {
1615
+ document.title = newState.title;
1616
+ }
1617
+ const effectiveLogical = newState.finalHref ?? logicalHref;
1618
+ if (newState.finalHref) {
1619
+ window.history.replaceState(history.state, "", _basePath + effectiveLogical);
1620
+ }
1621
+ setCurrentHref(normalizeHref(effectiveLogical));
1622
+ if (destKey) {
1623
+ pendingScrollRef.current = { type: "restore", key: destKey };
1624
+ } else {
1625
+ window.scrollTo({ top: 0, behavior: "instant" });
1626
+ }
1627
+ } finally {
1628
+ if (navVersion.current === myVersion) {
1629
+ setIsNavigating(false);
1630
+ }
1610
1631
  }
1611
- }
1612
- }, [fetchPageState, basePath]);
1632
+ })();
1633
+ }, [fetchPageState, _basePath]);
1613
1634
  useEffect(() => {
1614
- const prevScrollRestoration = history.scrollRestoration;
1615
1635
  history.scrollRestoration = "manual";
1616
1636
  if (!getHistoryKey(history.state)) {
1617
1637
  history.replaceState({ ...history.state ?? {}, _furinKey: generateHistoryKey() }, "");
1618
1638
  }
1619
- return () => {
1620
- history.scrollRestoration = prevScrollRestoration;
1621
- };
1622
1639
  }, []);
1640
+ useLayoutEffect(() => {
1641
+ const instruction = pendingScrollRef.current;
1642
+ if (!instruction) {
1643
+ return;
1644
+ }
1645
+ pendingScrollRef.current = null;
1646
+ if (instruction.type === "restore") {
1647
+ try {
1648
+ const raw = sessionStorage.getItem(SCROLL_STORAGE_KEY);
1649
+ const positions = raw ? JSON.parse(raw) : {};
1650
+ const y = positions[instruction.key] ?? 0;
1651
+ window.scrollTo({ top: y, behavior: "instant" });
1652
+ } catch {
1653
+ window.scrollTo({ top: 0, behavior: "instant" });
1654
+ }
1655
+ return;
1656
+ }
1657
+ const destUrl = new URL(instruction.href, window.location.origin);
1658
+ if (destUrl.hash) {
1659
+ const id = decodeURIComponent(destUrl.hash.slice(1));
1660
+ const element = document.getElementById(id);
1661
+ if (element) {
1662
+ element.scrollIntoView({ behavior: "instant", block: "start" });
1663
+ }
1664
+ } else {
1665
+ window.scrollTo({ top: 0, behavior: "instant" });
1666
+ }
1667
+ }, [currentHref]);
1623
1668
  useEffect(() => {
1624
1669
  window.addEventListener("popstate", handlePopState);
1625
1670
  return () => window.removeEventListener("popstate", handlePopState);
1626
1671
  }, [handlePopState]);
1672
+ useEffect(() => {
1673
+ if (typeof window === "undefined") {
1674
+ return;
1675
+ }
1676
+ const handler = (e) => {
1677
+ if (e.defaultPrevented) {
1678
+ return;
1679
+ }
1680
+ const anchor = e.target.closest("a");
1681
+ if (!(anchor instanceof HTMLAnchorElement)) {
1682
+ return;
1683
+ }
1684
+ if (anchor.closest("a[data-furin-link]")) {
1685
+ return;
1686
+ }
1687
+ const logicalHref = shouldInterceptClick(anchor, e, _basePath, window.location.origin, window.location.pathname);
1688
+ if (logicalHref === null) {
1689
+ return;
1690
+ }
1691
+ e.preventDefault();
1692
+ navigate(logicalHref, { resetScroll: !logicalHref.includes("#") });
1693
+ };
1694
+ document.addEventListener("click", handler);
1695
+ return () => document.removeEventListener("click", handler);
1696
+ }, [navigate, _basePath]);
1627
1697
  useEffect(() => {
1628
1698
  if (typeof window === "undefined") {
1629
1699
  return;
@@ -1636,9 +1706,9 @@ function RouterProvider({
1636
1706
  invalidatePrefetch(path, type);
1637
1707
  invalidated.push({ path, type });
1638
1708
  });
1639
- if (autoRefresh && invalidated.length > 0) {
1640
- const currentPath = window.location.pathname + window.location.search;
1641
- if (shouldAutoRefreshPath(currentPath, invalidated)) {
1709
+ if (_autoRefresh && invalidated.length > 0) {
1710
+ const currentLogicalPath = normalizeHref(toLogical(window.location.pathname, _basePath)) + window.location.search;
1711
+ if (shouldAutoRefreshPath(currentLogicalPath, invalidated)) {
1642
1712
  refresh();
1643
1713
  }
1644
1714
  }
@@ -1649,7 +1719,7 @@ function RouterProvider({
1649
1719
  return () => {
1650
1720
  window.fetch = originalFetch;
1651
1721
  };
1652
- }, [invalidatePrefetch, refresh, autoRefresh]);
1722
+ }, [invalidatePrefetch, refresh, _autoRefresh]);
1653
1723
  let pageElement;
1654
1724
  if (state.notFound || !state.match) {
1655
1725
  pageElement = buildNotFoundPageElement(state.notFoundBoundaries ?? state.match?.segmentBoundaries ?? rootBoundaries, state.notFound ?? {});
@@ -1660,22 +1730,24 @@ function RouterProvider({
1660
1730
  });
1661
1731
  }
1662
1732
  return buildRouterTree({
1663
- basePath,
1733
+ basePath: _basePath,
1664
1734
  currentHref,
1665
1735
  navigate,
1666
1736
  prefetch,
1667
1737
  refresh,
1668
1738
  invalidatePrefetch,
1669
1739
  isNavigating,
1670
- defaultPreload,
1671
- defaultPreloadDelay,
1672
- defaultPreloadStaleTime
1740
+ defaultPreload: _defaultPreload,
1741
+ defaultPreloadDelay: _defaultPreloadDelay,
1742
+ defaultPreloadStaleTime: _defaultPreloadStaleTime
1673
1743
  }, pageElement, {
1674
1744
  digest: initialDigest,
1675
1745
  onReset: refresh,
1676
1746
  resetKey: currentHref
1677
1747
  });
1678
1748
  }
1749
+
1750
+ // src/link.tsx
1679
1751
  function computeLinkView({
1680
1752
  to,
1681
1753
  search,
@@ -1686,8 +1758,9 @@ function computeLinkView({
1686
1758
  }, router) {
1687
1759
  const logicalHref = buildHref(to, search, hash);
1688
1760
  const logicalHrefWithoutHash = buildHref(to, search, undefined);
1689
- const href = router.basePath + logicalHref;
1690
- const isActive = router.currentHref === logicalHrefWithoutHash;
1761
+ const isAbsolute = logicalHref.startsWith("http://") || logicalHref.startsWith("https://") || logicalHref.startsWith("//");
1762
+ const href = isAbsolute ? logicalHref : router.basePath + logicalHref;
1763
+ const isActive = !isAbsolute && router.currentHref === normalizeHref(logicalHrefWithoutHash);
1691
1764
  const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
1692
1765
  const extraProps = {
1693
1766
  ...inactiveProps && !isActive ? inactiveProps() : {},
@@ -1712,24 +1785,25 @@ function LinkInteractive({
1712
1785
  onMouseLeave,
1713
1786
  onFocus,
1714
1787
  children,
1788
+ href: _href,
1715
1789
  ...anchorProps
1716
1790
  }) {
1717
1791
  const router = useRouter();
1718
- const anchorRef = useRef(null);
1719
- const intentTimerRef = useRef(null);
1792
+ const anchorRef = useRef2(null);
1793
+ const intentTimerRef = useRef2(null);
1720
1794
  const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView({ to, search, hash, children, activeProps, inactiveProps }, router);
1721
1795
  const effectivePreload = preload ?? router.defaultPreload;
1722
1796
  const effectiveDelay = preloadDelay ?? router.defaultPreloadDelay;
1723
1797
  const effectiveStaleTime = preloadStaleTime ?? router.defaultPreloadStaleTime;
1724
- const triggerPrefetch = useCallback(() => {
1798
+ const triggerPrefetch = useCallback2(() => {
1725
1799
  router.prefetch(logicalHref, { staleTime: effectiveStaleTime });
1726
1800
  }, [router, logicalHref, effectiveStaleTime]);
1727
- useEffect(() => {
1801
+ useEffect2(() => {
1728
1802
  if (effectivePreload === "render") {
1729
1803
  triggerPrefetch();
1730
1804
  }
1731
1805
  }, [effectivePreload, triggerPrefetch]);
1732
- useEffect(() => {
1806
+ useEffect2(() => {
1733
1807
  if (effectivePreload !== "viewport" || !anchorRef.current) {
1734
1808
  return;
1735
1809
  }
@@ -1742,6 +1816,12 @@ function LinkInteractive({
1742
1816
  observer.observe(anchorRef.current);
1743
1817
  return () => observer.disconnect();
1744
1818
  }, [effectivePreload, triggerPrefetch]);
1819
+ useEffect2(() => () => {
1820
+ if (intentTimerRef.current !== null) {
1821
+ clearTimeout(intentTimerRef.current);
1822
+ intentTimerRef.current = null;
1823
+ }
1824
+ }, []);
1745
1825
  const isInternal = (url) => {
1746
1826
  try {
1747
1827
  return new URL(url, window.location.origin).origin === window.location.origin;
@@ -1751,7 +1831,11 @@ function LinkInteractive({
1751
1831
  };
1752
1832
  const handleClick = (e) => {
1753
1833
  onClick?.(e);
1754
- if (e.defaultPrevented || disabled) {
1834
+ if (e.defaultPrevented) {
1835
+ return;
1836
+ }
1837
+ if (disabled) {
1838
+ e.preventDefault();
1755
1839
  return;
1756
1840
  }
1757
1841
  if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
@@ -1785,9 +1869,10 @@ function LinkInteractive({
1785
1869
  triggerPrefetch();
1786
1870
  }
1787
1871
  };
1788
- return createElement("a", {
1872
+ return createElement2("a", {
1789
1873
  ref: anchorRef,
1790
1874
  href,
1875
+ "data-furin-link": true,
1791
1876
  onClick: handleClick,
1792
1877
  onMouseEnter: handleMouseEnter,
1793
1878
  onMouseLeave: handleMouseLeave,
@@ -1829,10 +1914,12 @@ function renderLinkElement(props, router) {
1829
1914
  onMouseEnter: _ome,
1830
1915
  onMouseLeave: _oml,
1831
1916
  onFocus: _of,
1917
+ href: _href,
1832
1918
  ...anchorProps
1833
1919
  } = props;
1834
- return createElement("a", {
1920
+ return createElement2("a", {
1835
1921
  href,
1922
+ "data-furin-link": true,
1836
1923
  ...isActive ? { "data-status": "active" } : {},
1837
1924
  ...anchorProps,
1838
1925
  ...extraProps,
@@ -1841,23 +1928,27 @@ function renderLinkElement(props, router) {
1841
1928
  }
1842
1929
  function Link(props) {
1843
1930
  if (typeof window === "undefined") {
1844
- return createElement(RouterContext.Consumer, {
1931
+ return createElement2(RouterContext.Consumer, {
1845
1932
  children: (routerCtx) => renderLinkElement(props, routerCtx ?? SSR_FALLBACK_ROUTER)
1846
1933
  });
1847
1934
  }
1848
- return createElement(LinkInteractive, props);
1935
+ return createElement2(LinkInteractive, props);
1849
1936
  }
1850
1937
  export {
1851
1938
  useRouter,
1939
+ toLogical,
1852
1940
  shouldRefetch,
1941
+ shouldInterceptClick,
1853
1942
  shouldAutoRefreshPath,
1854
1943
  pickDeepestNotFound,
1944
+ normalizeHref,
1855
1945
  classifySpaResponse,
1856
1946
  buildRouterTree,
1857
1947
  buildPageElement,
1858
1948
  buildNotFoundPageElement,
1859
1949
  buildHref,
1860
1950
  applyRevalidateHeader,
1951
+ SSR_FALLBACK_ROUTER,
1861
1952
  RouterProvider,
1862
1953
  RouterContext,
1863
1954
  Link
@@ -1137,7 +1137,7 @@ class MagicString {
1137
1137
  }
1138
1138
 
1139
1139
  // src/plugin/transform-client.ts
1140
- import { parseSync } from "oxc-parser";
1140
+ import { parse } from "yuku-parser";
1141
1141
  var bunTranspiler = new Bun.Transpiler({
1142
1142
  loader: "tsx",
1143
1143
  tsconfig: {
@@ -1288,9 +1288,10 @@ function removeUnusedSpecifiers(s, code, decl, refs) {
1288
1288
  }
1289
1289
  function deadCodeElimination(s) {
1290
1290
  const code = s.toString();
1291
- const { program, errors } = parseSync("dce.js", code);
1292
- if (errors.length > 0) {
1293
- console.error("[furin] DCE: failed to parse transformed output:", errors[0]?.message);
1291
+ const { program, diagnostics } = parse(code, { sourceType: "module" });
1292
+ const firstError = diagnostics.find((d) => d.severity === "error");
1293
+ if (firstError) {
1294
+ console.error("[furin] DCE: failed to parse transformed output:", firstError.message);
1294
1295
  return s;
1295
1296
  }
1296
1297
  const fresh = new MagicString(code);
@@ -1340,9 +1341,10 @@ function removeServerExports(s, source, program) {
1340
1341
  }
1341
1342
  function transformForClient(code, filename) {
1342
1343
  const plainJs = bunTranspiler.transformSync(code);
1343
- const { program, errors } = parseSync(filename, plainJs);
1344
- if (errors.length > 0) {
1345
- throw new Error(`Failed to parse ${filename}: ${errors[0]?.message}`);
1344
+ const { program, diagnostics } = parse(plainJs, { sourceType: "module" });
1345
+ const firstError = diagnostics.find((d) => d.severity === "error");
1346
+ if (firstError) {
1347
+ throw new Error(`Failed to parse ${filename}: ${firstError.message}`);
1346
1348
  }
1347
1349
  let s = new MagicString(plainJs);
1348
1350
  const removedServerCode = removeServerExports(s, plainJs, program);